akhauriyash/Code-Regression huggingface dataset:
#include<vector>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;

#define fir first
#define sec second

typedef long long LL;
typedef pair<LL,LL> PP;

namespace INPUT{
	const int L=1<<15;
	char _buf[L],*S,*T,c;
	char _gc(){
		if(S==T){
			T=(S=_buf)+fread(_buf,1,L,stdin);
			if(S==T) return EOF;
		}
		return *S++;
	}
	void readi(int &X){
		for(c=_gc();c<'0'||c>'9';c=_gc());X=c&15;
		for(c=_gc();c>='0'&&c<='9';X=X*10+(c&15),c=_gc());
	}
}
#define readi INPUT::readi

const int Maxn=150005;
const LL INF=(LL)1E18;

int N;
int ch[Maxn][2];
int w[Maxn][2];
vector<PP> V[Maxn];
bool flag;

#define cl ch[u][0]
#define cr ch[u][1]
#define wl w[u][0]
#define wr w[u][1]
void Dfs(int u,LL X){
	if(!u) return;
	if(!flag) return;
	Dfs(cl,X),Dfs(cr,X);
	if(!flag) return;
	if(!cl){V[u].push_back(PP(0,0));return;}
	V[u].clear();
	int il,jl,ir,jr;
	il=ir=0,jl=V[cr].size()-1,jr=V[cl].size()-1;
	while(il<V[cl].size()||ir<V[cr].size()){
		if(ir>=V[cr].size()||il<V[cl].size()&&V[cl][il].fir+wl>V[cr][ir].fir+wr){
			while(jl>=0&&V[cl][il].sec+wl+V[cr][jl].sec+wr>X) --jl;
			if(jl>=0){
				if(V[u].size()>0&&V[u][V[u].size()-1].fir==V[cl][il].fir+wl)
					{V[u][V[u].size()-1].sec=min(V[u][V[u].size()-1].sec,V[cr][jl].fir+wr);++il;continue;}
				if(V[u].size()>0&&V[u][V[u].size()-1].sec==V[cr][jl].fir+wr)
					{V[u][V[u].size()-1].fir=V[cl][il].fir+wl;++il;continue;}
				while(V[u].size()>0&&V[cr][jl].fir+wr<V[u][V[u].size()-1].sec) V[u].pop_back();
				V[u].push_back(PP(V[cl][il].fir+wl,V[cr][jl].fir+wr));
			}
			++il;
		}
		else{
			while(jr>=0&&V[cr][ir].sec+wr+V[cl][jr].sec+wl>X) --jr;
			if(jr>=0){
				if(V[u].size()>0&&V[u][V[u].size()-1].fir==V[cr][ir].fir+wr)
					{V[u][V[u].size()-1].sec=min(V[u][V[u].size()-1].sec,V[cl][jr].fir+wl);++ir;continue;}
				if(V[u].size()>0&&V[u][V[u].size()-1].sec==V[cl][jr].fir+wl)
					{V[u][V[u].size()-1].fir=V[cr][ir].fir+wr;++ir;continue;}
				if(V[u].size()>0&&V[cl][jr].fir+wl<V[u][V[u].size()-1].sec) V[u].pop_back();
				//	{++ir;continue;}
				V[u].push_back(PP(V[cr][ir].fir+wr,V[cl][jr].fir+wl));
			}
			++ir;
		}
	}
	if(V[u].size()==0){flag=false; return;}
	V[cl].clear(),V[cr].clear();
}

int main(){
	readi(N);
	memset(ch,0,sizeof(ch));
	for(int fa,i=2;i<=N;++i){
		readi(fa);
		if(ch[fa][0])
			ch[fa][1]=i,readi(w[fa][1]);
		else
			ch[fa][0]=i,readi(w[fa][0]);
	}
	LL stt=-1,mid,lst=(LL)5E10;
	while(stt+1<lst){
		mid=(stt+lst)>>1;
		flag=true,Dfs(1,mid);
		if(flag) lst=mid;
		else stt=mid;
	}
	cout<<lst;
	return 0;
}


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

int main(){
  int N, M;
  cin >> N >> M;
  int n;
  for(int i=0; i<M; i++){
    cin >> n;
    N -= n;
  }
  if(N<0){
	cout << -1 << endl;
    return 0;
  }
  cout << N << endl;
  return 0;
}

Measured memory_bytes: 3624
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		List<Long> trans = new ArrayList<>();

		for (int i = 0; i < 5; i++) {
			trans.add(sc.nextLong());
		}

		Long min_t = Collections.min(trans);
		Long temp = (long)Math.ceil((double)N/(double)min_t);
		System.out.println(5 + temp - 1);

	}

}

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

int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

int main() {
    int64_t K, ans = 0;
    cin >> K;
    for (int64_t i = 1; i <= K; i++) {
        for (int64_t j = 1; j <= K; j++) {
            for (int64_t k = 1; k <= K; k++) {
                ans += gcd(i, gcd(j, k));
            }
        }
    }

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


Measured memory_bytes: 3620
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005


ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=1000000000000;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}


/////////////////////////////////////////////////////////////////



int a[26];
int main(){
    int h,w;cin>>h>>w;
    rep(i,0,h-1){
        string s;cin>>s;
        rep(j,0,w-1){
            a[s[j]-'a']++;
        }
    }
    rep(i,0,25)a[i]=a[i]%4;
    int count=0;
    int odd=0;
    if(h%2==0&&w%2==0){
        rep(i,0,25){
            if(a[i]!=0){cout<<"No"<<endl;return 0;}
        }
        cout<<"Yes"<<endl;
    }else if(h%2==0){
        rep(i,0,25)if(a[i]%2==1){odd++;a[i]--;}
        if(odd>=1){cout<<"No"<<endl;return 0;}
        rep(i,0,25)count+=a[i];
        if(count>h)cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }else if(w%2==0){
        rep(i,0,25)if(a[i]%2==1){odd++;a[i]--;}
        if(odd>=1){cout<<"No"<<endl;return 0;}
        rep(i,0,25)count+=a[i];
        if(count>w)cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }else{
        rep(i,0,25)if(a[i]%2==1){odd++;a[i]--;}
        if(odd>=2){cout<<"No"<<endl;return 0;}
        else{
            rep(i,0,25)count+=a[i];
            if(count>h+w-2)cout<<"No"<<endl;
            else cout<<"Yes"<<endl;
        }
    }
    
    return 0;
}

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

using namespace std;

using piles_type = pair<long, long>;

piles_type play(const piles_type& piles, int round = 0)
{
  if (piles.first < 2 and piles.second < 2) {
    // cerr << round << ": " << piles.first << ", " << piles.second << endl;
    return round % 2 ? make_pair(1l, 0l) : make_pair(0l, 1l);
  }

  piles_type results = make_pair(0l, 0l);
  if (piles.first >= 2) {
    for (long i = 2; i <= piles.first; i += 2) {
      piles_type new_piles = make_pair(piles.first - i, piles.second + i/2);
      // cerr << round + 1 << ": " << new_piles.first << ", " << new_piles.second << endl;
      auto result = play(new_piles, round + 1);
      results.first += result.first;
      results.second += result.second;
    }
  }
  if (piles.second >= 2) {
    for (long i = 2; i <= piles.second; i += 2) {
      piles_type new_piles = make_pair(piles.first + i/2, piles.second - i);
      // cerr << round + 1 << ": " << new_piles.first << ", " << new_piles.second << endl;
      auto result = play(new_piles, round + 1);
      results.first += result.first;
      results.second += result.second;
    }
  }
  return results;
}

int main()
{
  long a, b;
  cin >> a >> b;
  long diff = abs(a - b);
  cout << (diff >= 2 ? "Alice" : "Brown") << endl;
  return 0;

  /*
  piles_type piles;
  cin >> piles.first >> piles.second;
  auto results = play(piles);
  */
  // cerr << results.first << " " << results.second << endl;
  for (long i = 0; i < 12; ++i) {
    for (long j = i; j < 12; ++j) {
      auto results = play(make_pair(i, j));
      cout << i << ", " << j << ": " << (results.first >= results.second ? "Alice" : "Brown") << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
//	-*- mode: C++ -*-
// Merge Sort
//	 Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function.
//
// Merge(A, left, mid, right)
//   n1 = mid - left;
//   n2 = right - mid;
//   create array L[0...n1], R[0...n2]
//   for i = 0 to n1-1
//     do L[i] = A[left + i]
//   for i = 0 to n2-1
//     do R[i] = A[mid + i]
//   L[n1] = SENTINEL
//   R[n2] = SENTINEL
//   i = 0;
//   j = 0;
//   for k = left to right-1
//     if L[i] <= R[j]
//       then A[k] = L[i]
//            i = i + 1
//       else A[k] = R[j]
//            j = j + 1
//
// Merge-Sort(A, left, right){
//   if left+1 < right
//     then mid = (left + right)/2;
//          call Merge-Sort(A, left, mid)
//          call Merge-Sort(A, mid, right)
//          call Merge(A, left, mid, right)
// Input
//	 In the first line n is given. In the second line, n integers are given.
//
// Output
//	 In the first line, print the sequence S. Two consequtive elements should be separated by a space character.
//
//	 In the second line, print the number of comparisons.
//
// Constraints
//	 n ≤ 500000
//	 0 ≤ an element in S ≤ 10^9
// Sample Input 1
//	 10
//	 8 5 9 2 6 3 7 1 10 4
// Sample Output 1
//	 1 2 3 4 5 6 7 8 9 10
//	 34

#include <iostream>
#include <vector>
#include <climits>

class CB
{
public:
	CB(){}
	~CB(){}
	void	Sort();

private:
	unsigned int					n	{0};
	std::vector<unsigned long long>	S	{};
	unsigned int					count	{0};

	void	Merge(unsigned int	left,
				  unsigned int	mid,
				  unsigned int	right);

	void	MergeSort(unsigned int	left,
					  unsigned int	right);
};

void	CB::Sort()
{
	std::cin >> n;

	for(unsigned int i = 0; i < n; i++){
		unsigned long long	Si;
		std::cin >> Si;
		S.push_back(Si);
	}

	MergeSort(0, n);

	for(unsigned int i = 0; i < n; i++){
		std::cout << S[i];
		if(i < n - 1){
			std::cout << ' ';
		}
	}

	std::cout << std::endl;

	std::cout << count << std::endl;
}

void	CB::Merge(unsigned int	left,
				  unsigned int	mid,
				  unsigned int	right)
{
	unsigned int	n1	= mid - left;
	unsigned int	n2	= right - mid;

	std::vector<unsigned long long>	L	{};
	std::vector<unsigned long long>	R	{};

	for(unsigned int i = 0; i < n1 ; i++){
		L.push_back(S[left + i]);
	}
	L.push_back(ULLONG_MAX);

	for(unsigned int i = 0; i < n2; i++){
		R.push_back(S[mid + i]);
	}
	R.push_back(ULLONG_MAX);

	unsigned	int	i	{0};
	unsigned	int	j	{0};

	for(unsigned int k = left; k < right ; k++){
		count++;
		if(L[i] <= R[j]){
			S[k]	= L[i];
			i++;
		}
		else{
			S[k]	= R[j];
			j++;
		}
	}
}

void	CB::MergeSort(unsigned int	left,
					  unsigned int	right)
{
	if(left + 1 < right){
		unsigned int	mid	= (left + right) / 2;
		MergeSort(left, mid);
		MergeSort(mid, right);
		Merge(left, mid, right);
	}
}

int	main(int	argc,
		 char*	argv[])
{
	CB	cb;

	cb.Sort();

	return 0;
}



Measured memory_bytes: 12704
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int ha,ma,h,m,k,i,ans;
    char s[1000000];

    cin>>s;
    h=strlen(s);
    for(i=0;i<h;i++)
    {
        if(s[i]=='?')
        {
            if(s[i-1]=='P')
                s[i]='D';
            else if(s[i+1]=='D')
                s[i]='P';
            else if(s[i+1]=='?')
                s[i]='P';
            else
                s[i]='D';
        }
    }
  cout<<s<<endl;
  return 0;
}


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

int main(){
    ll n;
    cin >> n;
    priority_queue<pll, vector<pll>, greater<pll> > baque;
    rep(i,n){
        ll a, b;
        cin >> a >> b;
        baque.push(make_pair(b,a));
    }

    ll t = 0;
    while(!baque.empty()){
        pll p = baque.top();
        t += p.second;
        if(t > p.first){
            cout << "No\n";
            return 0;
        }
        baque.pop();
    }
    cout << "Yes\n";
}


Measured memory_bytes: 6128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

string sa,sb;
const int MN = 2010;
int a[MN],b[MN];
int N;

int needl[MN],needr[MN];

int calc(int L,int R,int i){
	chmax(L,i);
	int res = R*2 + L + (L-i);
	return res;
}

int solve(){
	rep(i,N){
		for(int t=0;;t++){
			int j = (i-t+N)%N;
			if(b[j]){
				needl[i] = t;
				break;
			}
		}
	}
	rep(i,N){
		for(int t=0;;t++){
			int j = (i+t)%N;
			if(b[j]){
				needr[i] = t;
				break;
			}
		}
	}
	int res = 1e9;
	rep(i,N){
		vector<int> difs;
		rep(x,N){
			if(a[(i+x)%N]!=b[x]) difs.pb((i+x)%N);
		}
		using P = pair<int,int>;
		vector<P> vp;
		for(int d:difs){
			if(needl[d]<=i) continue;
			vp.pb(P(needl[d],needr[d]));
		}
		sort(all(vp),greater<P>());

		int tmp = 1e9;
		int L = N-1, R = 0;

		for(P p:vp){
			L = p.fs;
			chmin(tmp,calc(L,R,i));
			chmax(R,p.sc);
		}
		L = 0;
		chmin(tmp,calc(L,R,i));

		if(vp.empty()) tmp = i;

		tmp += difs.size();

		chmin(res,tmp);
	}
	return res;
}

int main(){
	cin>>sa>>sb;
	N = sa.size();
	rep(i,N){
		a[i] = sa[i]=='1';
		b[i] = sb[i]=='1';
	}
	if(sb == string(N,'0')){
		if(sa == string(N,'0')) puts("0");
		else puts("-1");
		return 0;
	}
	int ans = 1e9;
	rep(tt,2){
		chmin(ans,solve());
		reverse(a,a+N);
		reverse(b,b+N);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pi 3.14159265358979323846
#define mod 1000000007
int main()
{
    IOS;
    ll a,b,c,d,e=0;
    cin>>a;
    b=a;
    while(b!=0)
    {
        b=b+a;
        b=b%360;
        e++;
    }
    cout<<e+1<<endl;
}

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


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = 100100100100100100;
const int mod = 1e9;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};


/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
vector<int> cs(vector<int> arr){vector<int> tmp;if(arr.size() == 0) return tmp;tmp.push_back(arr[0]);rep(i,1,arr.size()){tmp.push_back(tmp.back() + arr[i]);}return tmp;}



/* main */



signed main(){

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



 
    int a, b, k; 
    cin >> a >> b >> k;

    for(int i = 0; i < k; i++){
        if(i % 2 == 0){
            int t = a/2;
            a /= 2;
            b += t;
        }else{
            int t = b/2;
            b /= 2;
            a += t;
        }
    }

    cout << a << " " << b << endl;

    
   
    













}






    










    




    










Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a)  (a).begin(),(a).end()
#define Pi P<int,int>
#define elif else if

int a[100100][3];
int dp[100100][3];
signed main(){
  int n;
  cin>>n;
  fo(i,n){
    fo(j,3){
      cin>>a[i][j];
    }
  }
  fo(i,n){
    fo(j,3){
      fo(k,3){
        if(j==k)
          continue;
        dp[i+1][k]=max(dp[i+1][k],dp[i][j]+a[i][k]);
      }
    }
  }
  int ans;
  ans=max(dp[n][0],max(dp[n][1],dp[n][2]));
  cout<<ans<<endl;




}

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

int main() {
    int N, Q;
    std::cin >> N >> Q;
    std::vector<std::queue<int>> v(N);
    for (int q = 0; q < Q; ++q) {
        int t;
        std::cin >> t;
        if (t == 0) {
            int i, x;
            std::cin >> i >> x;
            v[i].push(x);
        } else if (t == 1) {
            int i;
            std::cin >> i;
            if (!v[i].empty()) std::cout << v[i].front() << std::endl;
        } else {
            int i;
            std::cin >> i;
            if (!v[i].empty()) v[i].pop();
        }
    }
    return 0;
}



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

int main() {
  int num_max,num_min;
  num_max = 0;
  num_min = 100000000000;
  vector<int> vec(3);
  for(int i=0;i<3;i++){
    cin >> vec.at(i);
  }
  for(int i=0;i<3;i++){
    num_max = max(vec.at(i),num_max);
  }
  for(int i=0;i<3;i++){
    num_min = min(vec.at(i),num_min);
  }
  cout << (num_max-num_min) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
 
using namespace std;
typedef long long int lli;
 
int main(){
	string x;
	cin>>x;
	int l=(int)x.length();
	deque<char> deq;
	rep(i,l){
		if(deq.empty())deq.push_back(x[i]);
		else if(deq.back()=='S'&&x[i]=='T')deq.pop_back();
		else deq.push_back(x[i]);
	}
	cout<<deq.size()<<endl;
}

Measured memory_bytes: 644
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long n, m;
std::priority_queue<long> que;

int main(){
    scanf("%ld%ld", &n, &m);
    for(int i = 0; i < n; i++){
        long a;
        scanf("%ld", &a);
        que.push(a);
    }
    for(int i = 0; i < m; i++){
        long x = que.top();
        que.pop();
        que.push(x/2);
    }
    long ans = 0;
    while(!que.empty()){
        ans += que.top();
        que.pop();
    }
    printf("%ld\n", ans);
}


Measured memory_bytes: 1400
import numpy as np

S = np.array(list(input()))
N = len(S)

cnt1 = 0
cnt2 = 0

for i in range(0, N):
    if i % 2 == 0:
        if int(S[i]) != 0:
            cnt1 = cnt1 + 1
    else:
        if int(S[i]) != 1:
            cnt1 = cnt1 + 1

for i in range(0, N):
    if i % 2 == 0:
        if int(S[i]) != 1:
            cnt2 = cnt2 + 1
    else:
        if int(S[i]) != 0:
            cnt2 = cnt2 + 1

print(min(cnt1, cnt2))

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a += b;
    c += d;
    if(a < c)       cout << "Right" << endl;
    else if(a > c)  cout << "Left" << endl;
    else            cout << "Balanced" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll k, a, b;
    cin >> k >> a >> b;
    if(b-a<=2 || k-1<a){
        cout << k+1 << endl;
    }
    else{
        ll ans = 0, cnt = 0;
        k -= a-1;
        ans += (b-a)*(k/2)+a;
        ans += k%2;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()
	N := readInt()
	a := make(map[int]int)
	for i := 0; i < N; i++ {
		x := readInt()
		a[x]++
	}
	var ans int64
	for x, nrx := range a {
		if x == nrx {
			continue
		}
		if x < nrx {
			ans += int64(nrx - x)
		} else {
			ans += int64(nrx)
		}
	}
	println(ans)
}


Measured memory_bytes: 7168
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=10;
double x[N],y[N];
int n;
double ans;
bool vis[N];
void dfs(int pre,int step,double sum) {
	if (step==n+1) {
		ans+=sum;
		return ;
	}
	for (int i=1;i<=n;++i) {
		if (!vis[i]) {
			vis[i]=true;
			if (step^1) dfs(i,step+1,sum+sqrt((x[i]-x[pre])*(x[i]-x[pre])+(y[i]-y[pre])*(y[i]-y[pre])));
			else dfs(i,step+1,sum);
			vis[i]=false;
		}
	}
}
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
		scanf("%lf%lf",&x[i],&y[i]);
	dfs(0,1,0);
	for (int i=1;i<=n;++i) ans/=i;
	printf("%.10lf\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<iostream>
 
using namespace std;
 
typedef long long ll;
 
const int N = 200005;
 
ll n,k;
int a[N];
 
ll pot[33];
 
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	pot[0] = 1;
	for(int i=1;i<30;i++){
		pot[i] = pot[i-1]*2;
	}
	
	cin>>n>>k;
	
	a[k] = 0;
	for(int i=k-1;i>0;i--){
		a[i] = a[i*2]+1;
	}
	
	ll sm = 0;
	for(int i=1;i<=n;i++){
		sm += pot[a[1] - a[i]];
	}
	
	long double ans = (1.0*sm)/(1.0*n)/(1.0*pot[a[1]]);
	cout<<fixed<<setprecision(12)<<ans;
	
	return 0;
}


Measured memory_bytes: 4104
// Shuffle.c
// １つのアルファベットが描かれた n 枚のカードの山をシャッフルします。
// 1回のシャッフルでは、下から h 枚のカードをまとめて取り出し、それを残ったカードの山の上に積み上げます。
// カードの山は以下のように１つの文字列で与えられます。
//   abcdeefab
// 最初の文字が一番下にあるカード、最後の文字が一番上にあるカードを示しています。
// 例えば、これを h が 4 でシャッフルすると、最初の4文字 abcd が、
// 残りの文字 eefab の末尾へ連結されるので以下のようになります：
//   eefababcd
// このシャッフルを何回か繰り返します。
// カードの山の最初の並び（文字列）と h の列を読み込み、最後の並び（文字列）を出力するプログラムを作成して下さい。
// 【入力】
// 複数のデータセットが入力として与えられます。各データセットは以下の形式で与えられます：
//   最初の並びを表す文字列
//   シャッフル回数 m
//   h1
//   h2
//     .
//     .
//   hm
// 最初の並びを表す文字列が "-" のとき入力の終わりとします。
// 【制約】
// 1 ≤ 文字列の長さ≤ 200
// 1 ≤ m ≤ 100
// 1 ≤ hi < 文字列の長さ
// データセットの数は10を超えない
// 【出力】
// 各データセットに対して、最後の並び（文字列）を１行に出力して下さい。
// 【例】
// 入力：
// aabc
// 3
// 1
// 2
// 1
// vwxyz
// 2
// 3
// 4
// -
// 出力：
// aabc
// xyzvw
#include<stdio.h>
#include<string.h>

void shuffle( char str[], int h) {
  char sub[201] = {};
  int i, j;

  for ( i=0; i < h; i++) {
    sub[i] = str[i];
  }
  sub[i] = '\0';

  for ( j=h; j < strlen( str); j++) {
    str[j-h] = str[j];
  }
  str[j-h] = '\0';

  strcat( str, sub);
}

int main( void) {
  char cards[201];
  int shuffle_num;
  int h;

  while ( 1) {
    scanf( "%s", cards);
    if ( strcmp( cards, "-") == 0) break;

    scanf( "%d", &shuffle_num);
    for ( int i = 0; i < shuffle_num; i++) {
      scanf( "%d", &h);
      shuffle( cards, h);
    }
    printf( "%s\n", cards);
  }

  return 0;
}



Measured memory_bytes: 2104
//#define local
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
#ifdef local
#include "debug.cpp"
#else
#define debug(...)
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    ll n,m; cin >> n >> m;
    if(n*m == 1)cout << 1 << endl;
    else cout << (n == 1 || m == 1? n*m - 2:(n-2)*(m-2)) << endl;
}

Measured memory_bytes: 3528
import Data.List.Split
import Data.Maybe
import qualified Data.ByteString.Char8 as B
main=mapM_(putStrLn.solve).chunksOf 2.map(map(fst.fromJust.B.readInt).B.words).B.lines=<<B.getContents
solve[[n],as]=if(c+(if b==1||b>1&&c/=0 then 1 else 0)<=(if a/=0 then a+1 else 0))then"Yes"else"No"
  where(a,b,c)=foldr f(0,0,0)as
f v(a,b,c)
  |v`mod`4==0=(a+1,b,c)
  |v`mod`2==0=(a,b+1,c)
  |otherwise=(a,b,c+1)

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

int main() {
  string S;
  cin>>S;
  if(S=="Sunny"){
    cout<<"Cloudy"<<endl;
  }
  else if(S=="Cloudy"){
    cout<<"Rainy"<<endl;
  }
  else if(S=="Rainy"){
    cout<<"Sunny"<<endl;
  }

  return 0;

}



Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)

    val n = sc.nextInt()
    val x = new Array[Int](n)
    for (i <- 0 until n) {
      x(i) = sc.nextInt()
    }
    val average = x.sum / n
    var ans = 0
    var ans2 = 0
    var ans3 = 0
    for (i <- 0 until n) {
      ans += math.pow((average - x(i)), 2).toInt
      ans2 += math.pow((average - 1 - x(i)), 2).toInt
      ans3 += math.pow((average + 1 - x(i)), 2).toInt
    }

    println(math.min(ans, math.min(ans2, ans3)))
  }
}


Measured memory_bytes: 27196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> ba(m);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    ba[i] = P(b, a);
  }
  sort(all(ba));
  int bri = -1;
  int ans = 0;
  rep(i, m) {
    int a = ba[i].second, b = ba[i].first;
    if(bri < a) {
      bri = b - 1;
      ans++;
    }
  }
  cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  string c;
  stack<int> s;
  while (cin >> c) {
    bool sign = false;
    if (c == "+" || c == "-" || c == "*") sign = true;
    if (sign) {
      int a, b;
      a = s.top(), s.pop();
      b = s.top(), s.pop();
      if (c == "+") s.push(a + b);
      if (c == "-") s.push(b - a);
      if (c == "*") s.push(a * b);
    } else {
      int r = 0;
      rep(i, c.size()) r *= 10, r += c[i] - '0';
      s.push(r);
    }
  }
  cout << s.top() << '\n';
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int n; cin >>n;
  string a,b,c; cin >>a >>b >>c;
  int res = 0;
  rep(i, n){
    if (a[i] == b[i] && a[i] == c[i]) continue;
    res++;
    if (a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) continue;
    res++;
  }
  cout <<res <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
    	int D = scanner.nextInt();
      	int T = scanner.nextInt();
      	int S = scanner.nextInt();
      	scanner.close();
      	if (S * T >= D) {
        	System.out.println("Yes");
        } else {
       		System.out.println("No");
        }
    }
}

Measured memory_bytes: 35688
N = int(input())
K = int(input())
X = input().split()
count = 0
for i in range(N) :
    if int(X[i]) <= K - int(X[i]) :
        count += 2*(int(X[i]))
    else :
        count += 2*(abs(K - int(X[i])))
print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
typedef long long ll;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
string s;
int k;
int INFi=1000000000;
ll INFl=1000000000000000;

struct UnionFind{
    vector<int> par;//初期化
    vector<int> rank;//高さ
    UnionFind(int n=0):par(n),rank(n,0){
        for(int i=0;i<n;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);//経路圧縮
    }
    void unite(int x,int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry) return;
        if(rank[rx]<rank[ry]) rank[rx]=ry;
        else rank[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};
vector<int> color(100000,-1);
vector<pi> G[100000];
void dfs(int s,int c){
    color[s]=c;
    for(int i=0;i<G[s].size();i++){
        if(color[G[s][i].first]==-1){
            if(G[s][i].second%2==0) dfs(G[s][i].first,(c==1?1:0));
            else dfs(G[s][i].first,(c==1?0:1));
        }
    }
}
int main(){
    int N;cin>>N;
    int u,v,w;
    for(int i=0;i<N-1;i++){
        cin>>u>>v>>w;
        u--;v--;
        G[u].push_back(pi(v,w));
        G[v].push_back(pi(u,w));
    }
    dfs(0,1);
    for(int i=0;i<N;i++) cout<<color[i]<<endl;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;


int main() {
    string s; cin >> s;
    int k; cin >> k;
    set<string> st;
    int n = sz(s);

    rep(pos, n) {
        REP(j, 1, k+1) {
            string sub = s.substr(pos, j); //sのpos番目からj要素抜き出す
            st.insert(sub);
        }
    }

    auto it = st.begin();
    rep(i, k-1) it++;
    cout << *it << endl;

}

Measured memory_bytes: 1664
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();

		int sum = 0;
		for(int i = 0; i < n; i++) {
			int a = sc.nextInt();
			for(int j = 1; j <= d; j+=a) {
				sum++;
			}
		}

		System.out.println(sum + x);
	}
}


Measured memory_bytes: 21972
#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 <cmath>

using namespace std;
typedef long long ll;

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

int count(int N)
{

        int cnt = 0;
        while (N)
        {
                cnt++;
                N /= 10;
        }
        return cnt;
}

int main()
{
        int N;
        cin >> N;
        map<int, int> mp;
        rep(i, N)
        {
                int a;
                cin >> a;
                mp[a]++;
        }
        int ans = 0;
        for (auto itr = mp.begin(); itr != mp.end(); itr++)
        {
                if ((itr->second) % 2 == 1)
                {
                        ans++;
                }
        }

        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 4992
#include<cstdio>
#include<cstring>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;
const int P=1000000007;
template<typename T>inline void rd(T&x){int fl=0,ch;while(ch=getchar(),ch<48||57<ch)fl^=!(ch^45);x=(ch&15);while(ch=getchar(),47<ch&&ch<58)x=x*10+(ch&15);if(fl)x=-x;}
template<typename T>inline void pt(T x){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);}
template<typename T>inline void pt(T x,int ch){pt(x),putchar(ch);}
template<typename T>inline T max(const T&x,const T&y){return x<y?y:x;}
template<typename T>inline T min(const T&x,const T&y){return x<y?x:y;}
const int N=100005;
int n,ans=1,cnt[26];char s[N];
int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;++i)++cnt[s[i]-'a'];
	for(int i=0;i<=25;++i)ans=1ll*ans*(cnt[i]+1)%P;
	printf("%d\n",(ans-1+P)%P);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  int n, k;
  ll sum = 0;
  cin >> n >> k;
  vector<int> v(n);
  rep(i,n)
  {
    cin >> v[i];
  }
  sort(v.begin(), v.end(), greater<int>());
  if (n <= k) {
    cout << 0;
  } else {
    for (int i = k; i < n; i++) {
      sum += v[i];
    }
    cout << sum;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int maxn=100000+5;
int a[maxn];
int n;
int cnt[maxn];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++){
        cnt[a[i]+1]++,cnt[a[i]]++,cnt[a[i]-1]++;
    }
    int tmp=0,tmpmax=0;
    for(int i=0;i<maxn;i++) {
        if(tmp<cnt[i]){
            tmp=cnt[i],tmpmax=i;
        }
    }
    int Ans=0;
    for(int i=1;i<=n;i++){
        if(a[i]+1==tmpmax || a[i]==tmpmax || a[i]-1==tmpmax) Ans++;
    }
    printf("%d\n",Ans);
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int[] d = new int[6];
		int n = scan.nextInt();
		Dice[] dices = new Dice[n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < 6; j++){
				d[j] = scan.nextInt();
			}
			dices[i] = new Dice(d);
		}

		boolean flag = false;
		boolean ans = true;
		for(int i = 0; i < n - 1; i++){
			for(int j = i + 1; j < n; j++){
				flag = dices[i].equals(dices[j]);
				if(flag == true){
					ans = false;
					break;
				}
			}
		}
		System.out.println(ans? "Yes" : "No");
	}
}

class Dice{
	int[] d_ = new int[6];
	public static final int
		TOP = 0, SOUTH = 1, EAST = 2,
		WEST = 3, NORTH = 4, BOTTOM = 5;

	public Dice(int[] d){
		for(int i = 0; i < 6; i++){
			d_[i] = d[i];
		}
	}

	public boolean equals(Dice diceB){
		boolean result = false;
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 4; j++){
				result = Arrays.equals(this.d_, diceB.d_);
				if(result == true)break;
				diceB.rollEast();
			}
			for(int j = 0; j < 4; j++){
				result = Arrays.equals(this.d_, diceB.d_);
				if(result == true)break;
				diceB.rollSouth();
			}
			result = Arrays.equals(this.d_, diceB.d_);
			if(result == true)break;
			diceB.rollRight();
		}
		return result;
	}

	public void setTop(int num){
		if(num == d_[EAST]){
			this.rollWest();
		} else if(num == d_[WEST]){
			this.rollEast();
		} else if(num == d_[SOUTH]){
			this.rollNorth();
		} else if(num == d_[NORTH]){
			this.rollSouth();
		} else if(num == d_[BOTTOM]){
			this.rollEast();
			this.rollEast();
		}
	}

	public void setSouth(int num){
		if(num == d_[EAST]){
			this.rollRight();
			this.rollRight();
			this.rollRight();
		} else if(num == d_[WEST]){
			this.rollRight();
		} else if(num == d_[NORTH]){
			this.rollRight();
			this.rollRight();
		}
	}

	public int show(int side){
		return d_[side];
	}

	public void rollEast(){
		int work = d_[TOP];
		d_[TOP] = d_[WEST];
		d_[WEST] = d_[BOTTOM];
		d_[BOTTOM] = d_[EAST];
		d_[EAST] = work;
	}

	public void rollWest(){
		int work = d_[TOP];
		d_[TOP] = d_[EAST];
		d_[EAST] = d_[BOTTOM];
		d_[BOTTOM] = d_[WEST];
		d_[WEST] = work;
	}

	public void rollSouth(){
		int work = d_[TOP];
		d_[TOP] = d_[NORTH];
		d_[NORTH] = d_[BOTTOM];
		d_[BOTTOM] = d_[SOUTH];
		d_[SOUTH] = work;
	}

	public void rollNorth(){
		int work = d_[TOP];
		d_[TOP] = d_[SOUTH];
		d_[SOUTH] = d_[BOTTOM];
		d_[BOTTOM] = d_[NORTH];
		d_[NORTH] = work;
	}

	public void rollRight(){
		int work = d_[SOUTH];
		d_[SOUTH] = d_[WEST];
		d_[WEST] = d_[NORTH];
		d_[NORTH] = d_[EAST];
		d_[EAST] = work;
	}
}

Measured memory_bytes: 29312
#include<cstdio>
#include<stdlib.h>
#include <bits/stdc++.h>

using namespace std;

//#define MAX_N 100
//#define MAX_N 200

int64_t A,B;
int64_t C,D;
//char R[MAX_N][MAX_M];
//int A[MAX_N];
int64_t mul(int64_t a,int64_t b);

int main(){
  cin>>A>>B>>C>>D;

  int64_t sum=0;
  
  int64_t ca1=A%C;
  int64_t ca2=A/C; 
  int64_t cb1=B%C;
  int64_t cb2=B/C;

  int64_t sumc=cb2-ca2+(ca1==0);
  

  int64_t da1=A%D;
  int64_t da2=A/D; 
  int64_t db1=B%D;
  int64_t db2=B/D;

  int64_t sumd=db2-da2+(da1==0);

  int64_t mu=mul(C,D);
  int64_t cda1=A%(mu);
  int64_t cda2=A/(mu); 
  int64_t cdb1=B%(mu);
  int64_t cdb2=B/(mu);

  int64_t sumcd=cdb2-cda2+(cda1==0);

  
  

  cout<<B-A+1-(sumc+sumd-sumcd)<<endl;
  
  return 0;
}

int64_t mul(int64_t a,int64_t b)
{
  int64_t x = a * b;

  int64_t tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  int64_t r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
  return x/b;
 
  return 0;
}


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

bool isDup(string s) {
    int l = s.length();
    if(l%2==1) return false;
    
    if(s.substr(0,l/2) == s.substr(l/2, l/2)) return true;
    return false;
}

int main(void){
    int N;
    string s;
    cin >> N;
    cin >> s;
    if(isDup(s)) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n, a, min, max;
    long sum;
    scanf("%d\n", &n);
    scanf("%d ", &a);
    min=a;
    max=a;
    sum=a;
    for(int i=1; i<n; i++){
        scanf("%d ", &a);
        if(min>a){
            min=a;
        }
        if(max<a){
            max=a;
        }
        sum += a;
    }
    printf("%d %d %ld\n", min, max, sum);
}


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

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> a(n);
  for(int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a.begin(), a.end());
  int o = 0;
  for(int i = 0; i < k; i++) o += a[i];
  printf("%d\n", o);
}

Measured memory_bytes: 3748
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


int main() {
	int N, M; cin >> N >> M;
	vector<P>shop;
	REP(i, N) {
		int a, b; cin >> a >> b;
		shop.push_back(make_pair(a, b));
	}
	sort(shop.begin(), shop.end());
	ll cost = 0;
	REP(i, N) {
		if (M >= shop[i].second) {
			cost += (ll)shop[i].second * (ll)shop[i].first;
			M -= shop[i].second;
		}
		else {
			cost += (ll)shop[i].first *(ll)M;
			M = 0;
		}
		if (M == 0)break;
	}
	print(cost);



	return 0;
}


Measured memory_bytes: 1400
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[][] a = new int[n][26];
		for(int i=0; i<n; i++) {
			String s = sc.next();
			for(int j=0; j<s.length(); j++) {
				int d = s.charAt(j)-'a';
				a[i][d]++;
			}
		}
		for(int d=0; d<26; d++) {
			int cnt = 500;
			for(int i=0; i<n; i++) {
				cnt = Math.min(a[i][d], cnt);
			}
			for(int i=0; i<cnt; i++) {
				System.out.print(Character.toChars('a'+d));
			}
		}
		sc.close();
	}


}


Measured memory_bytes: 35732
N=int(input())
a=input()
a_=a__=[int(i) for i in a.split()]
b=input()
b_=b__=[int(i) for i in b.split()]
c=input()
c_=c__=[int(i) for i in c.split()]
sat=0
first=a_[0]-1
sat=sat+b_[first]
for x in a_:
    if x>N:
        a_.remove(x)
for x in b_:
    if x<1 or x>50:
        b__=b_.remove(x)
for x in c_:
    if x<1 or x>50:
        c__=c_.remove(x)
a__=list(dict.fromkeys(a_))
if len(a__) ==len(a_) and len(c__)==len(c_) and len(b__)==len(b_) and 2<=N<=50:
    for x in range(1,N):
        if a_[x]==1+a_[x-1]:
            sat=sat+b_[(a_[x])-1]+c_[(a_[x])-2]
        else:
            sat=sat+b_[(a_[x])-1]
    if sat!=0:
        print(sat)

Measured memory_bytes: 9160
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using graph = vector<vector<int>>;

int f(const graph& g, vector<int>& d, int s)
{
    if (d[s] != -1) return d[s];
    int res = 0;
    for (const auto& c : g[s]) { res = max(res, f(g, d, c) + 1); }
    return d[s] = res;
}

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

    graph g(n);
    vector<bool> is_root(n, true);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].emplace_back(y);
        is_root[y] = false;
    }
    vector<int> d(n, -1);
    for (int i = 0; i < n; i++) { f(g, d, i); }

    int ans = 0;
    for (int i = 0; i < n; i++) { ans = max(ans, d[i]); }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8832
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vector<double> x(n), y(n), tmp(n);
    for(int i = 0; i < n; ++i){
        cin >> x[i] >> y[i];
        tmp[i] = i;
    }
    double res = 0;
    double cnt = 0;
    do{
        for(int i = 0; i < n-1; ++i){
            double X = x[tmp[i+1]]-x[tmp[i]];
            double Y = y[tmp[i+1]]-y[tmp[i]];
            res += sqrt(X * X + Y * Y);
        }
        cnt += 1;
    }while(next_permutation(tmp.begin(), tmp.end()));
    res /= cnt;
    cout << fixed << setprecision(10);
    cout << res << endl;
}

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

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

    ll w = N / (A + B);
    ll x = w * A;
    ll rem = min(A, N % (A + B));
    
    cout << x + rem << endl;
}


Measured memory_bytes: 256