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

using namespace std;

int dx[4] = {0,-1,0,1}; //left,up,right,down
int dy[4] = {-1,0,1,0};

int main(){
    int H,W;
    cin >> H >> W;
    vector<string> S;

    for (int i=0; i<H; ++i)
    {
        string str;
        cin >> str;
        S.push_back(str);
    }

    vector< vector<char> > ans(H,vector<char>(W,'.'));

    for (int i=0; i<H; ++i)
    {
        for (int j=0; j<W; ++j)
        {
            for (int k=0; k<4; ++k)
            {
                int ni = i + dx[k], nj = j + dy[k];
                if(ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
                if (S[i][j] == '#' && S[ni][nj] == '#') ans[i][j] = ans[ni][nj] = '#';
            }
        }
    }

    bool can = true;
    for (int i=0; i<H; ++i)
    {
        for (int j=0; j<W; ++j)
        {
            if (S[i][j] != ans[i][j])
            {
                can = false;
                break;
            }  
        }
    }
    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

#define IO ios_base::sync_with_stdio(0);cin.tie(0);

int main()
{
  IO;
  int h, w; cin >> h >> w;
  vector <vector <int>> a(h, vector <int> (w, 0));
  int bal = 0;

  for (int i = 0; i < h; ++i)
  for (int j = 0; j < w; ++j) {
    if (a[i][j] == 0)
    {
      ++bal;
      a[i][j] = bal;
    }
    a[i][w - j - 1] = a[i][j];
    a[h - i - 1][j] = a[i][j];
  }

  map <int, int> m;
  for (auto elem : a)
  for (auto elem1 : elem)
      m[elem1]++;

  vector <int> st;
  for (auto elem : m)
    st.push_back(elem.second);

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

  m.clear();
  for (int i = 0; i < h; ++i)
  for (int j = 0; j < w; ++j)
  {
    char c; cin >> c;
    m[(int)(c - 'a')]++;
  }

  for (auto elem : m) {
    while (elem.second > 0) {
    auto it = upper_bound(st.begin(), st.end(), elem.second);
    if (it == st.begin())
    {
      cout << "No" << endl;
      return 0;
    }
    else {
      --it;
      elem.second -= *it;
      st.erase(it);
    }
    }
  }
  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 512
N,M=map(int,input().split())
Lm=0
Rm=N
ans=0

for i in range(M):
    Lt,Rt=map(int,input().split())
    if Lm < Lt:
        Lm = Lt
    if Rm > Rt:
        Rm = Rt
if Rm < Lm:
    print(0)
else:
    print(Rm-Lm+1)


Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // double
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ios::sync_with_stdio(false);
  while(1) {
      int a,b;
      cin >> a >> b;
      if(a == 0 && b == 0) break;
      vector<vector<string>> data(a,vector<string>(b,"#"));
      rep(i,a) {
          rep(j,b) cout << data.at(i).at(j);
          cout << "\n";
      }
      cout << "\n";
  }
}


Measured memory_bytes: 3248
import copy

H, W, K = map(int, input().split())
C = [[c for c in input()] for _ in range(H)]
count = 0

for i in range(2 ** (H + W)):
    V = copy.deepcopy(C)
    for j in range(H + W):
        if (i >> j) & 1:
            if j < H:
                for k in range(W):
                    V[j][k] = "R"
            else:
                for k in range(H):
                    V[k][j - H] = "R"
    if sum(V, []).count("#") == K:
        count += 1

print(count)

Measured memory_bytes: 9352
#include "bits/stdc++.h"
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;

char t[303][303];

int main() {
    int N;
    scanf("%d", &N);
    forn(i, 0, N)
        forn(j, 0, N)
            scanf(" %c", &t[i][j]);
    
    ll ans = 0;
    forn(B, 0, N) {
        bool good = true;
        forn(i, 0, N)
            for (int j = 0; j < N; j++)
                if (t[i][(j + B) % N] != t[j][(i + B) % N])
                    good = false;
        ans += good;
    }
    
    printf("%llu\n", ans * N);
    return 0;
}



Measured memory_bytes: 512
#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>;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  string S;
  cin >> S;
  if(S == "SSS" ) cout << 0 << endl;
  else if (S == "SSR") cout << 1 << endl;
  else if (S == "SRS") cout << 1 << endl;
  else if (S == "RSS") cout << 1 << endl;
  else if (S == "SRR") cout << 2 << endl;
  else if (S == "RSR") cout << 1 << endl;
  else if (S == "RRS") cout << 2 << endl;
  else if (S == "RRR") cout << 3 << endl;
}


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

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

using namespace std;

int main(){
	int n,l[200]; cin>>n;
	rep(i,2*n) cin>>l[i];

	sort(l,l+2*n);

	int ans=0;
	rep(i,n) ans+=l[2*i];
	cout<<ans<<endl;

	return 0;
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll mod = 998244353;

  sort(all(a));

  ll aSum = 0;
  rep(i, n) aSum += a[i];

  vector<vector<ll>> dp(n+1, vector<ll>(aSum+5, 0));
  dp[0][0] = 1;

  rep(t, n){
    rep(r, aSum+5){
      if(0 < dp[t][r]){
        dp[t+1][r] += 2 * dp[t][r];
        dp[t+1][r] %= mod;
        dp[t+1][r+a[t]] += dp[t][r];
        dp[t+1][r+a[t]] %= mod;
      }
    }
  }

  ll res = 0;
  for(ll r = (aSum+1)/2; r < aSum+5; r++){
    res += dp[n][r];
    res %= mod;
  }

  ll ap = 1;
  rep(i, n){
    ap *= 3;
    ap %= mod;
  }

  ap -= 3*res;
  while(ap < 0) ap += mod;
  
  vector<vector<ll>> dp2(n+1, vector<ll>(aSum+5, 0));
  if(aSum%2 == 0){
    dp2[0][0] = 1;
    rep(t, n){
    rep(r, aSum+5){
      if(0 < dp2[t][r]){
        dp2[t+1][r] += dp2[t][r];
        dp2[t+1][r] %= mod;
        dp2[t+1][r+a[t]] += dp2[t][r];
        dp2[t+1][r+a[t]] %= mod;
      }
    }
  }
    ap += 3*dp2[n][aSum/2];
  }
  

  cout << ap%mod << endl;

  return 0;
}


Measured memory_bytes: 423872
from itertools import accumulate

N, K = map(int, input().split())
p = list(map(int, input().split()))
exp = [0] + [(pi+1)/2 for pi in p]
exp = list(accumulate(exp))
ans = 0
for i in range(N-K+1):
    ans = max(ans, exp[i+K]-exp[i])
print(ans)


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


using namespace std;


int main(){
    int K,A,B;
    cin >> K >> A >> B;
    if((A-A%K<B-B%K)|| A%K==0 || B%K==0) cout << "OK"<< endl;
    else cout <<"NG"<< endl;
    return 0;
}


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

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

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

double dist(vector<int> x, vector<int> y, int i, int j)
{
	return sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
}

int partialSum(int i, int j, const vector<int>& a, vector<vector<int>>& dp)
{
	
	if (dp[i][j] != -1) return dp[i][j];  // メモをチェック

	if (i == 0)  // 最終チェック
	{
		if (j == 0) return true;
		else return false;
	}

	int res = 0;
	if (partialSum(i - 1, j - a[i - 1], a, dp) == 1) res = 1;
	if (partialSum(i - 1, j, a, dp) == 1) res = 1;
	return dp[i][j] = res;
}

int main()
{
	string s;
	cin >> s;
	int zero = 0;
	int one = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == '0') zero++;
		else if (s[i] == '1') one++;
	}
	cout << min(zero, one) * 2 << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long intS
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    int n,i;
    
    cin >> n >> i;
    
    cout << n-i+1 << endl;
    
    
    
    
    
//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define vec vector<int,int> 
#define int long long 


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ios_base& scientific (ios_base& str);
	
	int t=1;
//	cin>>t;
	while(t--){
		int n,w;
		cin>>n>>w;
		int wei[n],val[n];
		int sum=0;
		rep(i,n){
			cin>>wei[i]>>val[i];
			sum+=val[i];
		}
		int dp[sum+1][n+1]={0};
		rep(i,sum+1){
			rep(j,n+1){
				dp[i][j]=INT_MAX;
			}
		}
		REP(i,1,sum+1){
			REP(j,1,n+1){
				if(val[j-1]<=i){
					int a=0;
					if(dp[i-val[j-1]][j-1]!=INT_MAX) {
						a=wei[j-1]+dp[i-val[j-1]][j-1];
					}
					else if(val[j-1]==i){
						a=wei[j-1];
					}
					else{
						a=INT_MAX;
					}
					dp[i][j]=min(dp[i][j-1],a);
				}
				else{
					dp[i][j]=dp[i][j-1];
				}
			}
		}
		int ans=0;
		rep(i,sum+1){
			if(dp[i][n]<=w){
				ans=max(ans,i);
			}
		}
		
		cout<<ans<<endl;
	}
	return 0;
}


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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);

int main() {
    fast_io;
    vector<vector<int>> A(3, vector<int>(3));

    for(int i=0;i<3;i++) {
        for(int j=0;j<3;j++) {
            cin>>A[i][j];
        }
    }

    int t;
    cin>>t;

    while(t--) {
        int n;
        cin>>n;

        for(int i=0;i<3;i++) {
            for(int j=0;j<3;j++) {
                if(A[i][j]==n) {
                    A[i][j]=-1;
                }
            }
        }
    }

    //row check, and col check

    for(int i=0;i<3;i++) {
        if((A[i][0]==-1&&A[i][1]==-1&A[i][2]==-1)|| A[0][i]==-1&&A[1][i]==-1&&A[2][i]==-1) {
            cout<<"Yes"<<endl;
            return 0;
        }
    }

    //diag check

    if((A[0][0]==-1&&A[1][1]==-1&&A[2][2]==-1)||(A[0][2]==-1&&A[1][1]==-1&&A[2][0]==-1)) {
        cout<<"Yes"<<endl;
        return 0;
    }

    cout<<"No"<<endl;



}




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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MOD 1000000007
#define INF 100100100

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

ll calc(ll a){
  ll ans = (a+1)/2;
  ans %= 2;
  if(a % 2 == 0) ans ^= a;
  return ans;
}

int main(){
  ll a, b;
  cin >> a >> b;
  cout << (calc(a-1) ^ calc(b)) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		String s= stdin.next();
		if(s.contains("a")&&s.contains("b")&&s.contains("c")) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    ll h; cin >> h;
    ll hit = h;
    if(hit == 1){
        cout << 1 << endl;
        return 0;
    }
    ll num = 1;
    ll cnt = 0;
    while(hit > 0){
        hit /= 2;
        cnt += num;
        num *= 2;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
B[]={' bh','!%~','!d9','"zX'};
*F=" %d %d %d\n\0 pre-meiji\0  taisho\0 showa\0  heisei";
y,m,d;
main(e){
	for(;~scanf(F,&y,&m,&d)&&y<3000;e?printf(F,y-B[e-1]/1136+1,m,d,printf(F+e*2+2)):puts(F+3))
		for(e=0;e<4&&y*1136+m*32+d>=B[e];e++);
}

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

l=[0]*(1000005)
for i in range(n):
    if l[a[i]]==1:
        l[a[i]]+=1

    if l[a[i]]==0:
        for j in range(1000000//a[i]+1):
            l[a[i]*j]+=1
    
cnt=0
for i in range(n):
    if l[a[i]]==1:
        cnt+=1
print(cnt)
            
        

Measured memory_bytes: 32380
#include <algorithm>
#include <iostream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
    stack<int> s1;
    stack<pair<int, int>> s2;
    string s;
    int sum = 0;
    cin>>s;
    for (int i = 0;i<s.size(); i++) {
        if (s[i] == '\\') {
            s1.push(i);
        } else if (s[i] == '/'&&s1.size()>0) {
            int j = s1.top();
            s1.pop();
            sum += i - j;
            int a = i - j;
            while (s2.size() > 0 && s2.top().first > j) {
                a += s2.top().second;
                s2.pop();
            }
            s2.push(make_pair(j, a));
        }
    }

    vector<int> ans;
    cout << sum << endl;
    while (s2.size() > 0) {
        ans.push_back(s2.top().second);
        s2.pop();
    }
    cout << ans.size();
    reverse(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++){
        cout<<" ";
        cout<<ans[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3244
#include <iostream>
#include <string>

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

    std::string Str1, Str2;
    std::cin >> Str1 >> Str2;

    std::size_t i = 0, j = 0;
    while (true)
    {
        if (i < Str1.size())
        {
            std::cout << Str1[i];
            ++i;
        }
        if (j < Str2.size())
        {
            std::cout << Str2[j];
            ++j;
        }
        if (i >= Str1.size() && j >= Str2.size())
        {
            break;
        }
    }
    std::cout << std::endl;

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

N=int(input())
A=list(map(int,input().split()))
if N%2==0:
    check={2*i+1:2 for i in range(0,N//2)}
else:
    check={2*i:2 for i in range(0,N//2+1)}
    check[0]=1

data=defaultdict(int)
for i in range(0,N):
    data[A[i]]+=1

if data==check:
    print(pow(2,N//2,10**9+7))
else:
    print(0)


Measured memory_bytes: 58604
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
    double a, b, c, s, l, h;
    double d, e, f, rad;
    cin >> a >> b >> c;
    f = acos(-1);
    rad = f*c/180;
    s = a*b*sin(rad)/2;
    d = a*a + b*b -2*a*b*cos(rad);
    e = sqrt(d);
    l = a + b + e;
    h = b*sin(rad);
    printf("%lf\n", s);
    printf("%lf\n", l);
    printf("%lf\n", h);
    return 0;
}


Measured memory_bytes: 3560
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	String a = sc.next();
    String b = sc.next();
    String c = a.substring(2)+a.substring(1,2)+a.substring(0,1);
    if (b.equals(c)){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 21588
int main(void)
{
	int m,f,r;
	
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		if(m == -1&&f == -1&&r == -1)break;
		
		if(m == -1||f == -1)printf("F\n");
			else
		if(m + f >= 80)printf("A\n");
			else
		if(m + f >= 65)printf("B\n");
			else
		if(m + f >= 50)printf("C\n");
			else
		if(m + f >=30){
			if(r >= 50)printf("C\n");
			else
			printf("D\n");
		}else
		printf("F\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string ans = "CODEFESTIVAL2016";
    string s;
    cin >> s;
    int cnt = 0;
    for( int i = 0; i < 16; ++i ) {
        if( s[i] != ans[i] ) ++cnt;
    }

    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool pallindrome(string str){
	int x=str.size();
	for(int i=0;i<x;i++)
		if(str[i]!=str[x-i-1]) return false;
	return true;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string str,h1,h2;
	cin>>str;
	int n=str.size();
	if(n%2==0)
	    h1=str.substr(0,(n-1)/2+1);
	else h1=str.substr(0,(n-1)/2);
	h2=str.substr((n-1)/2+1,n-1);
	if(pallindrome(str) && pallindrome(h1) && pallindrome(h2))
		cout<<"Yes";
	else 
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	k, n := readInt(), readInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}

	max := a[0] + k - a[n-1]
	for i := 0; i < n-1; i++ {
		d := 0
		if a[i+1] < a[i] {
			d = a[i+1] + k - a[i]
		} else {
			d = a[i+1] - a[i]
		}

		if d > max {
			max = d
		}
	}
	fmt.Println(k - max)
}


Measured memory_bytes: 3840
INF = float("inf")

def WarshallFloyd(M):
    N = len(M)
    for k in range(N):
        for j in range(N):
            for i in range(N):
                M[i][j] = min(M[i][j], M[i][k] + M[k][j])
    return M


N, M, *ABC = map(int, open(0).read().split())

E = [[INF] * (N + 1) for _ in range(N + 1)]
for a, b, c in zip(*[iter(ABC)] * 3):
    E[a][b] = c
    E[b][a] = c

D = WarshallFloyd(E)

print(sum(D[a][b] < c for a, b, c in zip(*[iter(ABC)] * 3)))

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

using namespace std;

int main(void)
{
  string s;

  cin>>s;

  if(s[1] == 'B')
  {
    cout<<"ARC"<<endl;
  }
  else if(s[1] == 'R')
  {
    cout<<"ABC"<<endl;
  }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define int long long
const int N=1005;
int n,a[3][N],f[3][N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
signed main()
{
	n=read();
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++)a[i][j]=read();
	memset(f,-63,sizeof(f));
	f[1][0]=0;
	for(int i=1;i<=n;i++)
	{
		f[1][i]=f[1][i-1]+a[1][i];
		f[2][i]=max(f[1][i],f[2][i-1])+a[2][i];
	}
	cout<<f[2][n];
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> A(n);
    for(int i=0; i<n; i++){
        cin >> A[i];
    }
    //a/b切り上げ： (a + (b - 1)) / b
    cout << 1+((n-k)+((k-1)-1))/(k-1) << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static String I = "IMPOSSIBLE";
	public static String B = "Bad";
	public static String G = "Good";
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = ni();
		int m = ni();
		int[] a = new int[n];

		int sum = 0;
		int count = 0;

		for (int i = 0; i < n; i++) {
			a[i] = ni();
			sum += a[i];
		}

		for (int i = 0; i < n; i++) {
			if (Math.ceil((double) sum / (double) (4.0 * m)) <= a[i]) {
				count++;
			}
		}

		if (count >= m) {
			out(Y);
		} else {
			out(N);
		}

	}

	/*
	 * 以下メソッド集
	 */
	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static int max(int a, int b) {
		return Math.max(a, b);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static int min(int a, int b) {
		return Math.min(a, b);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}
}


Measured memory_bytes: 22612
A, B, K = [int(ngzk) for ngzk in input().split()]
AB = B - A + 1
if AB <= K*2:
  for i in range(A, B+1):
    print(i)
else:
  for i in range(A, A+K):
    print(i)
  for i in range(B-K+1, B+1):
    print(i)

Measured memory_bytes: 3060
// AOJ 0056: Goldbach's Conjecture
// 2017.10.28 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

#define MAX  50000
#define HALF 2761		// prime[2760]=24989, prime[2761]=25013
char table[MAX+1];			// zero: if prime 
int sz, prime[5200] = {   	// prime[46] = 223, max sz = 5132
  3,  5,  7, 11, 13, 17, 19, 23, 29, 
 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 
 73, 79, 83, 89, 97,101,103,107,109,113, 
127,131,137,139,149,151,157,163,167,173, 
179,181,191,193,197,199,211,223 };
int ans[MAX+MAX] = {0,0,0,0,1,0};
char buf[10], *p;
char out[1206][5];

int main()
{
	int i, j, k;

	for (i = 0; i < 47; i++) {
		k = prime[i];
		for (j = k<<1; j < MAX; j += k) table[j] = 1;
	}
	for (sz = 0, i = 3; i <= MAX; i += 2) if (!table[i]) prime[sz++] = i;
	for (i = 0; i < HALF; i++) {
		k = prime[i];
		for (j = i; j < sz; j++) ans[k + prime[j]]++;
	}

	while (fgets(p=buf, 10, stdin) && *buf != '0') {
		i = 0; while (*p >= '0') i = (i<<3) + (i<<1) + (*p++ & 0xf);
		if (i & 1) putchar('1'-table[i-2]), putchar('\n');
		else {
			k = ans[i];
			if (!out[k][0]) sprintf(out[k], "%d", k);
			puts(out[k]);
		}
	}
	return 0;
}

Measured memory_bytes: 3040
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let k: i64 = sc.read();
    let mut a: Vec<i64> = sc.vec(n);
    let mut f: Vec<i64> = sc.vec(n);

    let a_sum = a.iter().sum::<i64>();
    if a_sum <= k {
        println!("0");
        return;
    }

    a.sort();
    a.reverse();
    f.sort();

    let mut ok = 1e15 as i64;
    let mut ng = 0;
    while ok - ng > 1 {
        let max = (ok + ng) / 2;
        let mut pay = 0;
        for i in 0..n {
            let cost = max / f[i];
            let head = a[i];
            pay += cmp::max(head - cost, 0);
        }
        if pay <= k {
            ok = max;
        } else {
            ng = max;
        }
    }
    println!("{}", ok);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 10492
#include <iostream>
#include <sstream>
#include <cmath>
using namespace std;

typedef long long ll;

string itos(ll x){stringstream ss;ss<<x;return ss.str();};

bool check(bool flg,ll x,ll y){
	string s = itos(y);
	ll sum = 0;
	for(int i=0;i<s.length();i++){
		sum += (s[s.length()-i-1] - '0') * pow(-10,i);
	}
	return sum == (flg ? -1 : 1) * x;
}

int main(void){
	ll x;

	while(cin>>x,x){
		bool flg = false;
		if(x < 0){
			flg = true;
			x = -x;
		}
		string s = itos(x);
	  ll ans = 0;
		ll p = 1;

		for(int i=0;i<s.length();i++,p*=10){
			ll digit = s[s.length()-i-1] - '0';

			if(digit == 0) continue;
			if(i % 2 == 0 && !flg || i % 2 == 1 && flg){
				ans += digit * p;

				if(ans >= p*10){
					ll tmp = ans / (p*10);
					ans = ans % (p*10) + (20 - tmp) * p * 10;
				}
			}
			else{
				ans += (20 - digit) * p;

				if(ans >= p*20){
					ans -= p*20;
				}
			}
		}
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;

struct Point {
	int x, y;
};

const double EPS = 1E-8;
Point h, d, p[20];
int n;
bool flag[20];

bool dfs(double t, int s) 
{
	int i;
	for (i = 0; i < n; i++) {
		if (!flag[i]) break;
	}
	if (i == n) return true;
	
	Point pp = (s == -1) ? h : p[s];
	for (i = 0; i < n; i++) {
		if (flag[i]) continue;
		if (hypot(d.x - p[i].x, d.y - p[i].y) - hypot(pp.x - p[i].x, pp.y - p[i].y) - t < EPS) return false;
	}
	
	for (i = 0; i < n; i++) {
		if (flag[i]) continue;
		flag[i] = true;
		if (dfs(t + hypot(pp.x - p[i].x, pp.y - p[i].y), i)) return true;
		flag[i] = false;
	}
	
	return false;
}

int main()
{	
	while (cin >> n >> h.x >> h.y >> d.x >> d.y, n | h.x | h.y | d.x | d.y) {
		memset(flag, false, sizeof(flag));
		for (int i = 0; i < n; i++) {
			cin >> p[i].x >> p[i].y;
		}
		cout << (dfs(0, -1) ? "YES" : "NO") << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
int n,g;
int gcd (int a, int b){
    if(a<b)swap(a,b);

    int c = a%b;
    while(c>0){
        a = b;
        b = c;
        c = a%b;
    }
    return b;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        int temp;
        cin>>temp;
        if(i==1){g=temp;}
        else{g=gcd(g,temp);}
    }
    cout<<g<<endl;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void){
   
    int a=0,b=0,c=0,d=0,x=0,y=0;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    
    x=a+b;
    y=c+d;
    if(x>y)printf("Left\n");
    else if(x==y)printf("Balanced\n");
    else if (x<y)printf("Right\n");
    
    
    return 0;

}


Measured memory_bytes: 128
H,W = map(int,input().split())
m = [list(map(int,input().split())) for _ in range(H)]


ans = []
for i in range(H):

    if i%2 == 0:##左->右
        for j in range(W):
            if m[i][j]%2:
                if j == W-1:
                    if i != H-1:
                        ans.append((i+1,j+1,i+2,j+1))
                        m[i+1][j] += 1
                else:
                    ans.append((i+1,j+1,i+1,j+2))
                    m[i][j+1] += 1
    else:##右->左
        for j in reversed(range(W)):
            if m[i][j]%2:
                if j == 0:
                    if i != H-1:
                        ans.append((i+1,j+1,i+2,j+1))
                        m[i+1][j] += 1
                else:
                    ans.append((i+1,j+1,i+1,j))
                    m[i][j-1] += 1

print(len(ans))
for i in ans:
    print(*i)

Measured memory_bytes: 26648
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
using namespace std;

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

	cout << (A - 1) * (B - 1) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int check(vector<int> x, vector<int> comb, int N, int i) {
  if (i == N - 1) {
    int count = 0;
    for (int j = -1; j < 2; ++j) {
      int prod = 1;
      for (int k = 0; k < comb.size(); ++k) {
        prod *= comb[k];
      }
      prod *= x[i] + j;
      if (prod % 2 == 0)
        ++count;
    }
    return count;
  }

  int count = 0;
  for (int j = -1; j < 2; ++j) {
    vector<int> a = comb;
    a.push_back(x[i] + j);
    count += check(x, a, N, i + 1);
  }
  return count;
}

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

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

  vector<int> x(0);
  cout << check(a, x, N, 0) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  int n;
  cin >> n;
  vecint a(n);
  REPe(e, a) cin >> e;
  vecint sum(n, 0);
  REP(i, n - 1) { sum[i] = a[i] ^ a[i + 1]; }
  int S = 0;
  for (int i = 0; i < n; i += 2) {
    S = S ^ sum[i];
  }
  vecint ans(n, 0);
  REP(i, n) { ans[i] = a[i] ^ S; }
  REP(i, n) cout << ans[i] << endl;
}


Measured memory_bytes: 5464
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll INF = 100000000000000000;

template <typename T>
struct Edge
{
    int to;
    T cost;
};

template <typename T>
struct WeightedGraph
{
    int n;
    vector<vector<Edge<T>>> g;
    
    WeightedGraph(int n) : n(n){
        g.resize(n);
    }
    
    void init(int n_){
        n = n_;
        g.resize(n_);
    }
    
    void add_edge(int from, int to, T cost){
        g[from].push_back((Edge<T>){to, cost});
    }
};

template <typename T>
vector<T> Dijkstra(WeightedGraph<T> &g, int s){
    typedef pair<T, int> P;
    int n = g.n;
    vector<T> d(n);
    fill(d.begin(), d.end(), INF);
    priority_queue<P, vector<P>, greater<P>> que;
    d[s] = 0;
    que.push(P(0, s));
    while(que.size()){
        P nowp = que.top();
        que.pop();
        if(d[nowp.second] < nowp.first) continue;
        for(Edge<T> e : g.g[nowp.second]){
            if(d[e.to] > d[nowp.second] + e.cost){
                d[e.to] = d[nowp.second] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    return d;
}

int main()
{
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;
    WeightedGraph<ll> g(n), h(n);
    for(int i = 0; i < m; i++){
        int u, v;
        ll a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        g.add_edge(u, v, a);
        g.add_edge(v, u, a);
        h.add_edge(u, v, b);
        h.add_edge(v, u, b);
    }
    vector<ll> d = Dijkstra(g, s);
    vector<ll> e = Dijkstra(h, t);
    P p[100005];
    for(int i = 0; i < n; i++) p[i] = P(1000000000000000 - d[i] - e[i], i);
    sort(p, p + n, greater<P>());
    int j = 0;
    for(int i = 0; i < n; i++){
        while(p[j].second < i) j++;
        cout << p[j].first << endl;
    }
}


Measured memory_bytes: 21164
#include<iostream>
int main() {
	int d;
	std::cin >> d;
	if (d == 25) {
		std::cout << "Christmas" << std::endl;
	}
	if (d == 24) {
		std::cout << "Christmas Eve" << std::endl;
	}
	if (d == 23) {
		std::cout << "Christmas Eve Eve" << std::endl;
	}
	if (d == 22) {
		std::cout << "Christmas Eve Eve Eve" << std::endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int iNum = sc.nextInt();
    sc.nextLine();
    String sValue = sc.nextLine();
    String[] sSplitStr = sValue.split(" ");
    String sResult;
    int iCnt1 = 0;
    int iCnt2 = 0;
    for (int i = 0; i < iNum; i++) {
      int iOut = Integer.parseInt(sSplitStr[i]);
      if (0 != (iOut % 2)) {
        continue;
      }
      iCnt1++;
      if (0 == (iOut % 3) || (0 == (iOut % 5))) {
        iCnt2++;
      }
    }
    if (iCnt1 == iCnt2) {
      sResult = "APPROVED";
    } else {
      sResult = "DENIED";
    }
    System.out.print(sResult);
  }
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
 
#define IOS 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sd(n)       scanf("%d", &n)
#define sdd(a,b)    scanf("%d %d", &a, &b)
#define sddd(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sld(n)      scanf("%lld", &n)
#define slld(a,b)   scanf("%lld %lld", &a, &b)
#define sllld(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define slu(n)      scanf("%llu", &n)
#define sllu(a,b)   scanf("%llu %llu", &a, &b)
#define slllu(a,b,c) scanf("%llu %llu %llu", &a, &b, &c)
#define ss(a)		scanf("%s", a)
#define inStrAftInSome cin.ignore(numeric_limits<streamsize>::max(),'\n')		//input string(with whitespace) after input something(char, int, bool, str)
#define all(a) 		a.begin(),a.end()
#define unq(x)      x.erase(unique(all(x)), x.end()
#define mp 			make_pair
#define mt 			make_tuple
#define sz(av) 		int((av).size())					//return size of vec
#define CLR(arr)    memset(arr, 0, sizeof(arr))			//assign 0 to whole arr
#define SET(vec)    memset(arr, -1, sizeof(arr))		//assign -1 to whole arr
#define CLRV(vec)	fill(vec.begin(), vec.end(), 0)		//assign 0 to whole vec
#define SETV(vec,n,a) vec.assign(n, a)	
#define vtd(rowsize,colsize,type,name) 		vector < vector <type> > name(rowsize,vector <type> (colsize)); 	//assign to first n elements value a in vec
#define SETB(a)		memset(a, true, sizeof(a))			//boolean array initialize by true value
#define CLRB(a)		memset(a, false, sizeof(a))			//boolean array initialize by false value
#define vintitr 	vector<int>::iterator
#define vlnlnitr 	vector<long long>::iterator
#define sintitr 	set<int>::iterator
#define slnlnitr 	set<long long>::iterator
#define aa			first
#define bb			second
#define mod 		1000000007
#define PI 			acos(-1.00)
#define psb 		push_back
#define ppb			pop_back
#define ppb			pop_back
#define psf			push_front
#define ppf			pop_front
#define in 			inset
#define rep(i, n) 	for(int i=0; i<n; i++)
#define repi(i,j,n) for(int i=j; i<n; i++)
#define rof(i, n)   for(int i=n-1; i>=0; i--)
#define roff(i, n, f)	for(int i = n-1; i>=f; i--)
#define min3(a,b,c) (min((c),min((a),(b))))
#define max3(a,b,c) (max((a),max((b),(c))))
#define __lcm(a, b)	a*b / __gcd(a, b)
#define __builtin_zerocount(a)	8*sizeof(a)-__builtin_popcount(a)-__builtin_clz(a)-__builtin_ctz(a)
#define D(t)        cerr << #t " = " <<t  << '\n'
#define DBG         cerr << "Hi!" << '\n'
 
 
typedef long long	 		ll;
typedef unsigned long long	llu;
typedef long double			ld;
typedef vector< int > 		vi;
typedef vector< vi >		vvi;
typedef pair<int, int> 		pii;
typedef tuple<int,int,int>  tiii;



int main()
{
	double a, b, x;	cin >> a >> b >> x;
	double v = a*a*b;
	double ans;
	if(x <= v / 2)
		ans = atan(2*x / (a * b * b));
	else
		ans = atan(a*a*a /(2 * v - 2 *x ));
	printf("%.6lf\n", 90 - ans * 180 / acos(-1));
    return 0;
}

Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    set<ll> s;
    rep(i, N) {
        ll d;
        cin >> d;
        s.insert(d);
    }
    print(s.size());
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define xx first
#define yy second
using namespace std;
const int MAXN=2e5+5;
int a[MAXN];
map<int,int> sv;
vector<int> tmp;
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sv[a[i]]++;
	}
	for(auto i:sv)
	{
		tmp.push_back(i.yy);
	}
	sort(tmp.begin(),tmp.end());
	int sz=tmp.size();
	int ans=0;
	for(int i=0;i<sz-k;i++)
	{
		ans+=tmp[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 11516
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7 ;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+3;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n;
      cin>>n;
      int a[n+1];
      for(int i=0;i<n+1;i++) cin>>a[i];
      int b[n];
      for(int i=0;i<n;i++) cin>>b[i];
      int ans=0;
      for(int i=0;i<n;i++)
      {
            int mn=min(b[i],a[i]);
            b[i]-=mn;
            ans+=mn;
            mn=min(b[i],a[i+1]);
            ans+=mn;
            b[i]-=mn;
            a[i+1]-=mn;
      }
      cout<<ans;
}
// I never lose. I either win or I learn

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

int main() {
  string S;
  cin >> S;
  int b_odd = 0, b_even = 0, w_odd = 0, w_even = 0;
  for (int i = 0; i < S.size(); i++) {
    if (i%2==1) {
      if (S[i]=='0') b_odd++;
      else w_odd++;
    }
    else {
      if (S[i]=='0') b_even++;
      else w_even++;
    }
  }
  cout << min((b_odd+w_even), (b_even+w_odd)) << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <list>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

#define LL long long

int binary_search(LL pos, LL ary[], int size) {
    int ok = 0;
    int ng = size;

    while (ng - ok > 1) {
        int mid = (ok + ng) / 2;
        if (ary[mid] <= pos) ok = mid;
        else ng = mid;
    }

    return ok;
}

int main() {
    int a, b, q;
    cin >> a >> b >> q;

    LL s[100002], t[100002];
    s[0] = -10000000000;
    for (int i=1; i < a + 1; i++) {
        cin >> s[i];
    }
    s[a + 1] = 2 * 10000000000;

    t[0] = -10000000000;
    for (int i=1; i < b + 1; i++) {
        cin >> t[i];
    }
    t[b + 1] = 2 * 10000000000;

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

        int ls = binary_search(x, s, a + 2);
        int rs = ls + 1;

        int lt = binary_search(x, t, b + 2);
        int rt = lt + 1;

        //cout << ls << " " << rs << " " << lt << " " << rt << endl;

        LL ans = 2 * 10000000000;
        ans = min(ans, abs(s[ls] - x) + abs(t[lt] - s[ls]));
        //cout << ans << endl;
        ans = min(ans, abs(s[ls] - x) + abs(t[rt] - s[ls]));
        ans = min(ans, abs(s[rs] - x) + abs(t[lt] - s[rs]));
        ans = min(ans, abs(s[rs] - x) + abs(t[rt] - s[rs]));

        ans = min(ans, abs(t[lt] - x) + abs(s[ls] - t[lt]));
        ans = min(ans, abs(t[lt] - x) + abs(s[rs] - t[lt]));
        ans = min(ans, abs(t[rt] - x) + abs(s[ls] - t[rt]));
        ans = min(ans, abs(t[rt] - x) + abs(s[rs] - t[rt]));

        cout << ans << endl;
    }
}


Measured memory_bytes: 2816
/*
	Created by : imay_10
	" It won't be EASY, but I'll make it "
*/

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

typedef long long int ll;
const int mod = 1e9+7;
const ll inf = 1e18;
const double pi = 3.1415926535897932384626;

// Utility for fast exponentiation
ll mpow(ll a,ll b,ll m){
    ll res=1;
    //a%=m;
    while(b){
    	if(b%2) res=res*a%m;
		a=a*a%m;
		b/=2;
	}
	return res;
}

// Utility for modular inverse
ll inv(ll a,ll m){
	return mpow(a,m-2,m);
}

// Utility for GCD Calculation
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}

// Utility for binomial coefficient
ll ncr(ll n,ll k)
{
    if(n<k)
        return 0;
    ll C[n + 1][k + 1];
    ll i,j;
    for(i=0;i<=n;i++){
        for(j=0;j<=min(i,k);j++){
            if (j==0 || j==i)
                C[i][j]=1;
            else
                C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    return C[n][k];
}

void solve(){
	//code
	int h, w, m;
	cin >> h >> w >> m;
	vector<pair<int, int>> arr(m);
	for (int i = 0; i < m; i++)
		cin >> arr[i].first >> arr[i].second;
 
	set<pair<int, int>> st;
	for (int i = 0; i < m; i++)
		st.insert(arr[i]);
 
	map<int, int> mpw, mph;
	for (int i = 0; i < m; i++)
		mpw[arr[i].first]++, mph[arr[i].second]++;
 
	int maxw = 0, maxh = 0;
	for (auto x : mpw)
		maxw = max(x.second, maxw);
	for (auto x : mph)
		maxh = max(x.second, maxh);
 
	set<int> stw, sth;
	for (auto x : mpw)
		if (x.second == maxw)
			stw.insert(x.first);
 
	for (auto x : mph)
		if (x.second == maxh)
			sth.insert(x.first);
 
	for (auto x : stw) {
		for (auto y : sth) {
			if (st.find({x, y}) == st.end()) {
				cout << maxw + maxh;
				return ;
			}
		}
	}
	cout << maxw + maxh - 1;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	solve();
 	return 0;
}


Measured memory_bytes: 75732
def main():
    from math import gcd

    K=int(input())
    cal=0
    for a in range(1,K+1):
        for b in range(1,K+1):
            i=gcd(a,b)
            for c in range(1,K+1):
                cal+=gcd(i,c)

    print(cal)


main()


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

signed main(){
    int N,T;
    int A[114514];
    cin >> N >> T;
    REP(i,N){cin >> A[i];}
    int min_now=INF;
    int diff=0;
    int R=1;
    REP(i,N){
        if(diff<A[i]-min_now){
            diff=A[i]-min_now;
            R=1;
        }else if(diff==A[i]-min_now){
            R++;
        }
        min_now=min(min_now,A[i]);
    }
    cout << R << endl;
    return 0;
}   


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

void b_cut_and_count(void) {
	string s;
	int n;

	cin >> n >> s;

	int max = 0;

	for (int i = 0; i < n; i++) {
		int l[27] = { 0 };
		int r[27] = { 0 };
		for (int j = 0; j < n; j++) {
			if (i <= j) l[s[j] - 'a']++;
			else        r[s[j] - 'a']++;
		}

		int cnt = 0;
		for (int i = 0; i < 27; i++) {
			if (l[i] != 0 && r[i] != 0) cnt++;
		}

		if (cnt > max)max = cnt;
	}

	cout << max << endl;
}

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

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

using namespace std;

int main(){
    
    int N;
    cin >> N;
    pair<pair<string, int>, int> R[N];
    
    vector<string> S(N);
    int P[N];
    
    for (int i = 0; i < N; i++) {
        cin >> S[i] >> P[i];
        R[i].first.first = S[i];
        R[i].first.second = -1*P[i];
        R[i].second = i+1;
    }
    
    
    sort(R, R+N);
    
    for (int i = 0; i < N; i++) {
        //cout << R[i].first.first << " " << R[i].first.second << " " << R[i].second << endl;
        cout << R[i].second << endl;
        
    }
    
}


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

int main(){
  int n ;
  string str = "No" ;
  cin >> n ;
  for(int i=1; i<10; i++){
    for(int j=1; j<10; j++){
      if(n==i*j){
        str = "Yes" ;
        break ;
      }
    }
  }
  cout << str << endl ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a, b;
  cin >> a >> b;
  if (a + b < 24) {
  	cout << a + b << "\n";
  }else {
  	cout << a + b - 24 << "\n";
  }
}

Measured memory_bytes: 256