akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

int main(){
	int w; cin >> w;
	string ans="";
	while(w){
		if(w%3==0){
			ans+='0';
			w/=3;
		}
		else if(w%3==1){
			ans+='+';
			w/=3;
		}
		else{
			ans+='-';
			w/=3;
			while(w%3==2){
				ans+='0';
				w/=3;
			}
			if(w%3==0){
				ans+='+';
				w/=3;
			}
			else{
				w++;
			}
		}
	}
	reverse(ans.begin(),ans.end());
	cout << ans << endl;
}


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

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

  int n = s.size();
  int64_t ans;

  for (int i = 0; i < (1 << (n-1)); i++) {
    int64_t sum = 0;
    int64_t tmp = s[0] - '0';
    for (int j = 0; j < n-1; j++) {
      if (i & (1 << j)) {
        sum += tmp;
        tmp = 0;
      }
      tmp = tmp * 10 + s[j+1] - '0'; 
    }
    sum += tmp;
    ans += sum;
  }

  cout << ans << endl;

}

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

template<typename T> class CumulativeSum2D{
    public:
        vector<vector<T>> sum;
        
        CumulativeSum2D(int w, int h);
        void add(int x, int y, T v);
        void build();
        T get(int sx, int sy, int gx, int gy);
};

template<typename T> CumulativeSum2D<T>::CumulativeSum2D(int w, int h){
    sum = vector<vector<T>>(h + 1, vector<T>(w + 1, 0));
}

template<typename T> void CumulativeSum2D<T>::add(int x, int y, T v){
    sum[x + 1][y + 1] += v;
}

template<typename T> void CumulativeSum2D<T>::build(){
    for (int i = 1; i < sum.size(); i++){
        for (int j = 1; j < sum[i].size(); j++){
            sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
        }
    }
}

template<typename T> T CumulativeSum2D<T>::get(int sx, int sy, int gx, int gy){
    gx++; gy++;
    return sum[gx][gy] - sum[sx][gy] - sum[gx][sy] + sum[sx][sy];
}
        

int main(){
    int n, m, q;
    cin >> n >> m >> q;
    CumulativeSum2D<ll> cs(n, n);
    for (int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        cs.add(l - 1, r - 1, 1);
    }

    cs.build();
    for (int i = 0; i < q; i++){
        int x, y;
        cin >> x >> y;
        cout << cs.get(x - 1, x - 1, y - 1, y - 1) << endl;
    }

    
    return 0;
}

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

int main(){
string S,T;
  cin>>S>>T;
  T+=T ;
 //  int c=0;
     // cout<<T<<endl;
  bool c=false;
  for(int i=0;i<=S.size();i++){
  if(T.substr(i,S.size())==S)
   c=true;
    //  c++;
  }
  if(c)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
n=gets.to_i
num=Array.new(5)
5.times do|i|
	num[i]=gets.to_i
end
if ((n-num.min)%num.min)!=0
	print 5+((n-num.min)/num.min)+1
else
	print 5+((n-num.min)/num.min)
end


Measured memory_bytes: 1788
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define re register
#define rep(i,s,t) for(re int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(re int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define pt(x) putchar(x)
#define pti(x) printf("%d",x)
#define ptll(x) printf("%lld",x)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
using namespace std;
il int ci(){
	re char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	re int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}
enum{N=17};
struct Edge{ int nxt,to; bool o; } bow[N*N*2];
int head[N];

int main(){
	int n= ci();
	int tot= 0;
	rep(x,0,n-1){
		int k=ci();
		rep(i,1,k){
			int y=ci()-1, z=ci();
			bow[++tot]=(Edge){head[x],y,bool(z)};
			head[x]=tot;
		}
	}
	int full=(1<<n)-1;
	int ans= 0;
	rep(S,0,full){
		bool fail= 0;
		int cnt= 0;
		rep(u,0,n-1) if( S&(1<<u) ){
			cnt++;
			each(i,u){
				int v=bow[i].to;
				bool o=bow[i].o;
				if( bool(S&(1<<v))!=o ){ fail=1; break; }
			}
			if( fail ) break;
		}
		if( fail==0 ){ ans= max(ans,cnt); }
	}
	pti(ans),pt('\n');
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
using namespace::std;
int main(){
  double W;
  double H;
  int x;
  int y;
  cin>>W>>H>>x>>y;
  double k = (W*H)/2;
  cout<<k<<" ";
  if((x==(W/2))&&(y==(H/2))){
    cout<<1;
  }else{
    cout<<0;
  }

}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
len_S = len(S)

char = ""
ac = [0] * len_S
val = 0
for i in range(N):
    char += S[i]
    # print(char)
    # print(char[len(char)-2:len(char)+1])
    if char[len(char)-2:len(char)+1] == "AC":
        val += 1
    ac[i] = val
# print(ac)

for _ in range(Q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    ans = ac[r] - ac[l]
    print(ans)

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

int solve(int a, int b, int c)
{
  if((a+b) <= c)
    return 0;
  return 1;
}
int main()
{
  int n, ans=0;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a, a+n);
  for(int i=0; i<n; i++)
  {
    for(int j=i+1; j<n; j++)
    {
      for(int k=j+1; k<n; k++)
      {
        if((a[i] + a[j] > a[k]) && a[i]!=a[j] && a[i]!=a[k] && a[j]!=a[k])
        {
          ans++;
         // cout<<a[i]<<" "<<a[j]<<" "<<a[k]<<endl;
        }
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {
  int n, r; cin >> n >> r;
  if (n >= 10) cout << r << endl;
  else cout << r + 100*(10-n) << endl;
}

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

int main()
{
  int N; cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  sort(A.begin(), A.end());
  bool f = 0;
  rep(i, N-1){
    if(A[i] == A[i+1]){
      f = 1;
      break;
    }
  }
  
  if(f) cout << "NO" << endl;
  else cout << "YES" << endl;
  return 0;
}


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


int main()
{
	int A,B,T;
	scanf("%d %d %d",&A,&B,&T);
	int i;
	int count = 0;
	for(i=1;i<=20;i++)
	{
		if(i*A>T)
		{
			break;
		}
		count+=B;
	}
	printf("%d\n",count);
} 

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

using namespace std;

int main() {
  int N;
  
  cin >> N;
  
  N = N % 10;
  
  if (N == 3) {
    cout << "bon" << endl;
  } else if (N == 0 || N == 1 || N == 6 || N == 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <array>
#include <vector>
#include <map>
#include <utility>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <string>

using namespace std;

int main(int argc, const char * argv[]) {
    
    int n;
    cin >>n;
    
    vector<int> a;
    
    for (int i = 0; i < n; i++) {
        int t;
        cin >>t;
        t--;
        a.push_back(t);
    }
    
    int count  = 0;
    for (int i = 0 ; i < n; i++) {
        if (a[a[i]] == i) {
            count++;
        }
    }
    
    cout << count/2<<endl;
    
    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;



int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    long long k;
    cin>>k;
    long long n=50;
    vector<long long> vi(50,0);
    long long d=k/n;
    long long r=k%n;
    for(auto &i:vi){
        i=49+d;
    }
    for(int i=0; i<n; i++){
        if(i<r) vi[i]++;
        else vi[i]-=r;
    }
    cout<<n<<endl;
    for(auto i:vi){
        cout<<i<<" ";
    }
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>


int main() {
    long K, A, B;

    std::cin >> K >> A >> B;

    long biscket = 1;
    if (A + 2 < B) {
        while (K > 0 && biscket < A) {
            biscket++;
            K--;
        }
        biscket += K / 2 * (B - A)  + K % 2;
    } else {
        biscket = K + 1;
    }

    std::cout << biscket << std::endl;
}


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


string multiply(string a,string b){
    string arr[b.length()];
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    for(int i=0; i<b.length(); i++){
        arr[i]="";
    }

    int value,carry;
    int maxlen=0;
    for(int i=0; i<b.length(); i++){
        for(int j=0; j<i; j++){
            arr[i]+='0';
        }
        carry=0;
        for(int j=0; j<a.length(); j++){
            value=carry;
            value+=(b[i]-'0')*(a[j]-'0');
            carry=value/10;
            value=value%10;
            stringstream ss;
            ss<<value;
            string imt;
            ss>>imt;
            arr[i]+=imt;
            ss.clear();
        }
        stringstream ss;
        ss<<carry;
        string imt;
        ss>>imt;
        arr[i]+=imt;
        ss.clear();
        carry=0;
        if(arr[i].length()>maxlen){
            maxlen=arr[i].length();
        }
    }
    
    int count;
    for(int i=0; i<b.length(); i++){
        count = maxlen-arr[i].length();
        for(int j=0; j<count; j++){
            arr[i]+='0';
        }
    }

    string output="";

    carry=0,value=0;
    for(int i=0; i<maxlen; i++){
        value=carry;
        for(int j=0; j<b.length(); j++){
            value+=arr[j][i]-'0';
        }
        carry=value/10;
        value=value%10;
        stringstream ss;
        ss<<value;
        string imt;
        ss>>imt;
        output+=imt;
        ss.clear();
    }
    stringstream ss;
    ss<<carry;
    string imt;
    ss>>imt;
    output+=imt;
    carry=0;
    ss.clear();

    reverse(output.begin(), output.end());
    return output;
}


int main()
{
    string a,b;
    cin>>a>>b;
    string ans=multiply(a,b);
   
    int flag=0;
    for(int x=0; x<ans.length(); x++){
        if(ans[x]!='0'||flag==1){
            cout<<ans[x];
            flag=1;
        }
    }
    cout<<"\n";

    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i;
    char a[100],b[100];
    scanf("%d",&n);
    scanf("%s %s",a,b);
    for(i=0;i<n;i++)
    {
        printf("%c%c",a[i],b[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
using namespace std;
 
int main(){
    double pai=3.141592653589;
    int n,tmp;
    int s[1000];
    double avg,total,ans;
    for(;;){
        scanf("%d",&n);
        if(n==0) break;
        total=0;
        ans=0;
        for(int j=0;j<n;j++){
            scanf("%d",&s[j]);
            total+=s[j];
        }
        avg=total/n;
        for(int k=0;k<n;k++){
            ans+=(s[k]-avg)*(s[k]-avg);
        }
        ans=sqrt(ans/n);
        printf("%.12lf\n",ans);
    }
 
    return 0;
}


Measured memory_bytes: 3176
#include <stdio.h>
int c[26];

int main(void) {
    char ch;
    while( scanf( "%c", &ch ) != EOF ) {
        if( 'a' <= ch && ch <= 'z' ){
            int n = ch - 'a';
            c[n]++;
        } else if( 'A' <= ch && ch <= 'Z' ) {
            int n = ch - 'A';
            c[n]++;
        }
    }
    for( int i = 0; i < 26; i++ ){
        printf( "%c : %d\n", 'a' + i, c[i] );
    }
    return 0;
}


Measured memory_bytes: 2604
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

int getans()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); 
    int n; cin >> n;
    vector<int> v(n);
    map<int, int> cnt[2];
    rep(i, n) cin >> v[i];
    rep(i, n)
    {
        cnt[i%2][v[i]]++;
    }

    int n0 = (n + 1) / 2;
    int n1 = n / 2;

    vector<pair<int, int>> vlist[2];

    for (auto itr = cnt[0].begin(); itr != cnt[0].end(); itr++) vlist[0].emplace_back(-itr->second, itr->first);
    for (auto itr = cnt[1].begin(); itr != cnt[1].end(); itr++) vlist[1].emplace_back(-itr->second, itr->first);
    sort(vlist[0].begin(), vlist[0].end());
    sort(vlist[1].begin(), vlist[1].end());
    if( vlist[0][0].second != vlist[1][0].second ) return n0 + vlist[0][0].first + n1 + vlist[1][0].first; 
    int vs0 = 0;
    int vs1 = 0;
    if( vlist[0].size() > 1 ) vs0 = -vlist[0][1].first;
    if( vlist[1].size() > 1 ) vs1 = -vlist[1][1].first;
    return min( n0 + vlist[0][0].first + n1 - vs1, n1 + vlist[1][0].first + n0 - vs0);
}

int main()
{
    cout << getans() << endl;
}

Measured memory_bytes: 9340
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

ll a[20010];
int main(){
	ll n,m,t;
	scanf("%lld%lld%lld",&n,&m,&t);
	rep(_,0,n){
		ll x;
		scanf("%lld",&x);
		rep(i,x-m,x+m)a[i]=1;
	}
	ll ans=0;
	rep(i,0,t)ans+=!a[i];
	printf("%lld\n",ans);
}


Measured memory_bytes: 2100
INF = float("inf")
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

D, G = nl()
problems = []
for i in range(D):
    p, c = nl()
    problems.append([p, c])

min_count = INF
import itertools
for p in itertools.product([False, True], repeat=D):
    point = 0
    count = 0
    max_false = -1
    for i in range(D):
        if not p[i]:
            max_false = i
        else:
            point += 100*(i+1)*problems[i][0] + problems[i][1]
            count += problems[i][0]
    if max_false == -1:
        if count < min_count:
            min_count = count
        continue
    if point + 100*(max_false+1)*(problems[max_false][0]-1) < G:
        continue
    left = max(G - point, 0)
    if left > 0:
        count += left // (100*(max_false+1))
        if left % (100*(max_false+1)) > 0:
            count += 1
    if count < min_count:
        min_count = count
print(min_count)



Measured memory_bytes: 3064
n=int(input())
from collections import Counter as co
var=co(list(map(int,input().split())))
ans=0
for k in var:
  p=var[k]
  if k-1 in var:p+=var[k-1]
  if k+1 in var:p+=var[k+1]
  
  ans=max(ans,p)
print(ans)

Measured memory_bytes: 14556
#include<iostream>
#include<cstdlib>
 
#define maxN 1000
using namespace std;
typedef long long ll;
 
 
int main(){
  ll X,Y,Z,A,B,C,N;
  cin >> X >> Y >> Z >> A >> B >> C >> N;
 
  ll numX[maxN] = {}, numY[maxN] = {}, numZ[maxN] = {};
 
  for(ll i=0;i<X;i++)numX[abs(i-A)%N]++;
  for(ll i=0;i<Y;i++)numY[abs(i-B)%N]++;
  for(ll i=0;i<Z;i++)numZ[abs(i-C)%N]++;
 
  ll numXY[maxN] = {};
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      numXY[(i+j)%N] += numX[i] * numY[j];
    }
  }
 
  ll numXYZ[maxN] = {};
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      numXYZ[(i+j)%N] += numXY[i] * numZ[j];
    }
  }
 
  for(int i=0;i<N;i++){
    cout << numXYZ[i] << ((i==N-1)?"\n":" ");
  }
 
  return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string s,t;
    cin>>s>>t;
    vector<char> lst(26);
    for(int i=0;i<26;i++)lst[i]='\0';
    for(int i=0;i<s.size();i++){
        if(!lst[s[i]-'a'])lst[s[i]-'a']=t[i];
        else {
            if(lst[s[i]-'a']!=t[i]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    for(int i=0;i<26;i++)lst[i]='\0';
    for(int i=0;i<t.size();i++){
        if(!lst[t[i]-'a'])lst[t[i]-'a']=s[i];
        else {
            if(lst[t[i]-'a']!=s[i]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 776
#include <cstdio>
#include <algorithm>
using namespace std;

int n,k;
char s[110];

int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",s+1);
    s[k]-='A'-'a';
    printf("%s",s+1);
    getchar(); getchar();
    return 0;
}

Measured memory_bytes: 128
coins=[500,100,50,10,5,1]
while 1:
    v=int(input())
    if v==0:
        break
    else:
        change=1000-v
        cnt=0
        for coin in coins:
            c=change//coin
            if c!=0:
                cnt+=c
                change-=coin*c
        print(cnt)


Measured memory_bytes: 5588
#include<bits/stdc++.h>                                                                                                                                                                                     
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);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 pb push_back
#define PII pair<int,int>
 
#define VS vector<string>
#define VI vector<int>
#define ll long long int
#define debug(x) cout << x << " :" <<#x << endl  
int main(void) {
    vector<bool> s(26);
    fill(s.begin(), s.end(), false);
    string a;
    cin >> a;
    REP(i, a.size()) {
        if(s[a[i] - 'a']) {
            cout << "no" << endl;
            break;
        }
        s[a[i] - 'a'] = true;
        if(i == a.size() - 1) cout << "yes" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();

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

    /* サイコロ1階ふって勝てる確率 */
    int cnt = max(n - (k - 1), 0);
    long double p = (double)cnt / n;

    /* コインをR回ふって勝てる確率 */
    int time = 1;
    int multi_cnt = 0;
    for (int i = n - cnt; i > 0; i--){
        /* 2のn乗倍してK以上になる個数 */
        if (i * pow(2, time) >= k){
            multi_cnt++;
        }
        else{
            p += pow(0.5, time) * ((double)multi_cnt / n);
            time++;
            multi_cnt = 0;
            i++;
        }
    }
    p += pow(0.5, time) * ((double)multi_cnt / n);

    cout << fixed << setprecision(9) <<  p << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	
	int a, b;
	int sum = 0;
	
	scanf("%d%d", &a, &b);
	
	if(a > b) {
		sum = a;
		a--;
	} else {
		sum = b;
		b--;
	}
	
	if(a > b) {
		sum += a;
	} else {
		sum += b;
	}
	
	printf("%d\n", sum);
	
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    ll sum = 0;
    for(int i = 1; i <= n; i++) {
        if(i % 3 != 0 && i % 5 != 0) sum += i;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3640
import collections

N,K = map(int,input().split())
A = input().split()

c = collections.Counter(A)
l = len(c)

if l <= K:
  print("0")
else:
  times = 0
  value = 0

  for k,v in sorted(c.items(), key=lambda x: -x[1]):
    if times >=K:
      break
    value += v
    times += 1
  
  print(N-value)

Measured memory_bytes: 44056
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#define ll long long
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=20000050;

string s1,s2;

int main()
{
	cin>>s1;
	cin>>s2;
	ll ans=maxn;
	int n=s1.length(),m=s2.length();
	for(int i=0;i<n;++i)
	  {
	  	  int k=0;
	  	  for(int j=0;j<m;++j)
	  	    {
	  	    	if(i+j>=n) k=maxn;
	  	    	if(s1[i+j]!=s2[j]) k++;
	  	    }
	  	  if(k<ans) ans=k;  
	  }
	cout<<ans<<endl;  
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
int main() {
    
    int  x,a;
    cin >> x >> a;
    int ans = 0;
    while(x > 0)
    {
        ++ans;
        x-=a;
    }
    cout << ans ;
    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	d := make([]int, n)
	for i := range d {
		sc.Scan()
		d[i], _ = strconv.Atoi(sc.Text())
	}

	sort.Ints(d)

	fmt.Println(d[len(d)/2] - d[len(d)/2-1])
}


Measured memory_bytes: 2048
def cmb(n):
    return int(n * (n-1) / 2)

def main():

    N = int(input())

    a_l = [0] * N

    nums = list(map(int, input().split()))
    for i in nums:
        a_l[i-1] += 1

    total = 0
    for j in a_l:
        if j > 1:
            total += cmb(j)

    for k in nums:
        if a_l[k-1] > 1:
            print(total - cmb(a_l[k-1]) + cmb(a_l[k-1] - 1))
        else:
            print(total)


if __name__ == '__main__':
    main()

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

int bs(vector<int> &arr, int l,int r,int x){
	int ans = -1;
	while(l <= r){
		int m = (l + r) / 2;
		if(arr[m] <= x){
			ans = m;
			l = m + 1;
		}
		else{
			r = m - 1;
		}
	}
	return ans;
}

int main() {
	int l, r, d;
	cin >> l >> r >> d;
	
	vector<int>cr;
	for(int i = l; i <= r;i++){
		cr.push_back(i);
	}
	int cnt = 0;
	for(int t = 1; t < 100000; t++){
		if(t * d > r){
			break;
		}
		else if (bs(cr, 0, (cr.size() - 1), t * d) != -1){
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0; 
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;
  vll a(n),b(n);
  ll t = 0;
  REP(i, n){
    cin >> t;
    a[i] = t-1;
  }
  REP(i, n)
    cin >> b[i];
  vll c(n-1);
  REP(i, n-1)
    cin >> c[i];

  ll ans = 0;
  REP(i, n){
    ans += b[a[i]];
    if(i == 0)
      continue;
    if(a[i] == a[i-1] + 1)
      ans += c[a[i-1]];
  }

  cout << ans << endl;
  
}


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

signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n), c(n);
  for (int &i : p) {
    cin >> i;
    i--;
  }
  for (int &i : c) cin >> i;
  ll ans = -1001001001;
  for (int i = 0; i < n; i++) {
    int now = i;
    vector<ll> vs;
    ll score = 0;
    while (true) {
      now = p[now];
      score += c[now];
      vs.push_back(score);
      if (now == i) break;
    }
    int sz = vs.size();
    for (int j = 0; j < sz; j++) {
      if (j + 1 > k) break;
      ll cnt = (k - j - 1) / sz;
      if (score <= 0) ans = max(ans, vs[j]);
      else ans = max(ans, vs[j] + cnt * score);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3756
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MAXN=int(1e5+5);
LL n;
int main()
{
    scanf("%lld",&n);
    for(LL i=sqrt(n)+1;i>=1;i--)
    if(n%i==0) {
        printf("%lld",i+(n/i)-2);
        return 0;
    }
}


Measured memory_bytes: 128
#多行(1行目で行数)
n = int(input())
list_a = [int(input()) for i in range(n)]


ma = max(list_a)

i_ma = list_a.index(ma)
list_aa = list_a[:]
list_aa.pop(i_ma)

ma2 = max(list_aa)


# print(list_a)
# print(list_aa)
# print(ma, ma2)


for ai in list_a:
    if (ai == ma):
        print(ma2)
    else:
        print(ma)

Measured memory_bytes: 14068
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r = Console.ReadLine().Split(' ');
            var N = r[0].ToInt();
            var M = r[1].ToInt();
            var a = N * (N - 1) / 2;
            var b = M * (M - 1) / 2;
            Console.WriteLine(a + b);
            Console.ReadLine();
        }
    }
}

public static class Extentions
{
    public static int ToInt(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }
}



Measured memory_bytes: 11092
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define s(v)       sort(v.begin(),v.end())
#define r(v)       reverse(v.begin(),v.end())
#define pf         printf
#define sf         scanf
#define GCD(x,y)   __gcd(x, y)
#define pb         push_back
#define ll         long long
#define vs         v.size()
#define ss         s.size()
using namespace std;
int main()
{
    ll int a,b,c,d,x,y,z,zz;
    cin>>a>>b>>c>>d;
    x=a*c;
    y=b*c;
    z=a*d;
    zz=b*d;

    ll int res=max(x,max(y,max(z,zz)));
    cout<<res<<endl;

    return 0;
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
	int A,B,C,D;
	cin>>A>>B>>C>>D;
while(1){
		C-=B;
	A-=D;

	if(A<=0 || C<=0){
		break;
	}
}
if(C<=0){
	cout<<"Yes";
}
else{
	cout<<"No";
}
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

ll n;
string s;

int main(){
	cin>>s;
  n=s.size();
  ll res=0;
  rep(i,n){
    if(i%2==1&&s[i]=='g')res++;
    else if(i%2==0&&s[i]=='p')res--;
  }
  cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

LL mod(LL x, LL md) {
	return ((x % md) + md) % md;
}

class Mint {
public:
	static LL md;
	LL x;
	Mint(LL _x) {
		x = mod(_x, md);
	}
	Mint(const Mint &y) {
		x = mod(y.x, md);
	}
};

void MintMyExgcd(LL a, LL b, LL &x, LL &y) {
	// solve equation ax + by = 1 (mod m)
	LL md = Mint::md;
	if (b == 0) {
		y = 0;
		x = 1;
		return ;
	}
	MintMyExgcd(b, a % b, x, y);
	LL t = y;
	y = mod(x - (a / b) * y, md);
	x = t;
}

LL MintNY(LL x) {
	if (x == 0) {
		return 1;
	}
	LL md = Mint::md;
	LL a, b;
	MintMyExgcd(x, md, a, b);
	while (a < 0) {
		a += md;
	}
	return a;
}

/* LL gcd(LL a, LL b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
} */

Mint operator+(Mint a, Mint b) {
	return Mint(mod(a.x + b.x, Mint::md));
}
Mint operator-(Mint a, Mint b) {
	return Mint(mod(a.x - b.x, Mint::md));
}
Mint operator*(Mint a, Mint b) {
	return Mint(mod(a.x * b.x, Mint::md));
}
Mint operator/(Mint a, Mint b) {
	Mint c = Mint(MintNY(b.x));
	return Mint(mod(a.x * c.x, Mint::md));
}

Mint operator-(Mint a) {
	return Mint(-a.x);
}
bool operator==(Mint a, Mint b) {
	return a.x == b.x;
}
bool operator!=(Mint a, Mint b) {
	return a.x != b.x;
}
bool operator>(Mint a, Mint b) {
	return a.x > b.x;
}
bool operator<(Mint a, Mint b) {
	return a.x < b.x;
}
bool operator>=(Mint a, Mint b) {
	return a.x >= b.x;
}
bool operator<=(Mint a, Mint b) {
	return a.x <= b.x;
}

void operator+=(Mint &a, Mint b) {
	a = a + b;
}
void operator-=(Mint &a, Mint b) {
	a = a - b;
}
void operator*=(Mint &a, Mint b) {
	a = a * b;
}
void operator/=(Mint &a, Mint b) {
	a = a / b;
}

ostream& operator<<(ostream &out, Mint a) {
	out << a.x;
	return out;
}

istream& operator>>(istream &in, Mint &a) {
	in >> a.x;
	return in;
}

Mint factorial(LL n) {
	if (n == 0) {
		return Mint(1);
	}
	Mint res = 1;
	for (LL i = 1; i <= n; ++i) {
		res *= i;
	}
	return res;
}
Mint multiRange(LL s, LL t) {
	Mint res = 1;
	for (LL i = s; i <= t; ++i) {
		res *= i;
	}
	return res;
}

Mint getC(LL n, LL k) {
	if (n - k < k) {
		return getC(n, n - k);
	}
	return multiRange(n - k + 1, n) / factorial(k);
}

Mint getA(LL n, LL k) {
	return multiRange(n - k + 1, n);
}

Mint countNonNegativeDivision(LL n, LL k) {
	return getC(n + k - 1, k - 1);
}
Mint countPositiveDivision(LL n, LL k) {
	if (n < k) {
		return 0;
	}
	if (k <= 0) {
		return 0;
	}
	return getC(n - 1, k - 1);
}
Mint quickMod(Mint a, LL b) {
	Mint res = 1;
	while (b > 0) {
		if (b % 2) {
			res *= a;
		}
		a *= a;
		b /= 2;
	}
	return res;
}

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

LL Mint::md = 1000000007;

int main() {
	LL res = 0;
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			for (int k = 1; k <= n; ++k) {
				res += (LL)(gcd(i, j, k));
			}
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << 6 - a - b << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		if(a + b >= c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 25684
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int t = sc.nextInt();
    
    int minutes = (int) (t + 0.5) / a;
    int amounts = minutes * b;
    
    System.out.println(amounts);
  }
}

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

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

	if(a == b && b == c) {
		cout << "No";

	} else if(a != b && b !=c && a != c) {
		cout << "No";
	} else if(a == b || b == c || a == c) {
		cout << "Yes";
	}

	return 0;
}


Measured memory_bytes: 256
N = int(input())
K = int(input())
l = [int(i) for i in input().split()]
zero_kyori = 0
K_kyori = 0
kyori_list = []

for i in range(N):
    zero_kyori = (l[i] - 0) * 2
    K_kyori = (abs(l[i] - K)) * 2
    kyori_list.append(min(zero_kyori, K_kyori))

print(sum(kyori_list))


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

using namespace std;

int main() {
	long long N;
	cin >> N;
	long long length = log10(N);
	long long sum = 9 * length;
	N -= pow(10, length) - 1;
	for(int i = 0; i < length; i++)
		N /= 10;
	sum += N;
	cout << sum << endl;
}

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

using namespace std;

#define rep(i,n) for(long i=1;i<=n;i++)

const long inf=20000000000;

int main(){
  long a,b,q;
   cin >> a >> b >>q;
 
  vector<long> s(a+2),t(b+2);
   s[0]=-1*inf;
   t[0]=-1*inf; 
  rep(i,a) cin >> s[i];
  rep(i,b) cin >> t[i];
   s[a+1]=inf;
   t[b+1]=inf;
  
   
  rep(i,q) {
    long res=inf;
    long x; 
    cin >> x;
 
  long shrine=upper_bound(s.begin(),s.end(),x)-s.begin();
  long temple=upper_bound(t.begin(),t.end(),x)-t.begin();
  
    res=min(res,min(abs(t[temple]-x),abs(s[shrine]-x))+abs(t[temple]-s[shrine]));
    res=min(res,min(abs(t[temple-1]-x),abs(s[shrine]-x))+abs(t[temple-1]-s[shrine]));
    res=min(res,min(abs(t[temple]-x),abs(s[shrine-1]-x))+abs(t[temple]-s[shrine-1]));
    res=min(res,min(abs(t[temple-1]-x),abs(s[shrine-1]-x))+abs(t[temple-1]-s[shrine-1]));
  
  cout << res << endl;
  }
    
}
  

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

vector<long>kai(200001);

long ncrmodp(long n,long r,long p){
    long ans = 1;
    ans = kai[n];
    long tmp = 1;
    tmp = kai[r];
    tmp *= kai[n-r];
    tmp %= p;
    
    for(long i=1;i<=p-2;i*=2){
        if(i & (p-2)){
            ans *= tmp;
            ans %= p;
        }
        tmp *= tmp;
        tmp %= p;
    }
    return ans;
}

int main(){
    int n,m,k;
    cin >> n >> m >> k;
    long const mod = 998244353;
    
    kai[0] = 1;
    for(int i=1;i<=200000;i++){
        kai[i] = kai[i-1]*i;
        kai[i] %= mod;
    }

    
    vector<long>nm1(n,0);
    nm1[0] = 1;
    for(int i=1;i<n;i++){
        nm1[i] = nm1[i-1] * (m-1);
        nm1[i] %= mod;
    }
    long ans = 0;
    
    for(int i=0;i<=k;i++){
        long tmp = ncrmodp(n-1,i,mod);
        tmp *= m;
        tmp %= mod;
        tmp *= nm1[n-1-i];
        tmp %= mod;
        ans += tmp;
        ans %= mod;
    }

    cout << ans << endl;
    
}


Measured memory_bytes: 6428
#include<bits/stdc++.h>
using namespace std;
int i,j,n,m,c;
bool r;
int main(){
  for(cin>>n,i=n;;i++){
    for(j=2,r=true;j<=i/2;j++)if(i%j==0)r=false;
    if(r)return cout<<i,0;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <regex>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    long k, t;
    cin >> k >> t;
    long mx = -1;
    REP(i,t) {
        long a;
        cin >> a;
        mx = max(mx, a);
    }
    
    cout << max(mx - 1 - (k - mx), 0l) << endl;
}


Measured memory_bytes: 256
// -*- compile-command: "g++ -g -Wno-return-type -Wall -Wextra -DLOCAL -std=c++11 -D_GLIBCXX_DEBUG e.cpp -oe && ./e " -*-
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
#define int LL
#define vc vector
#define pb push_back
#define pr pair
#define fi first
#define se second
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define f(i,n) for(int i=0;i<(n);i++)
#define fr(i,n) for(int i=(n);i--;)
#define fv(i,v) f(i,sz(v))

int n,m;

struct Linfun{
	int a,b;
	Linfun(int a,int b):a(a),b(b){}
	int eval(int x){ return a*x+b; }
	void operator+=(Linfun r){
		a+=r.a;
		b+=r.b;
	}
	void operator-=(Linfun r){
		a-=r.a;
		b-=r.b;
	}
};

struct Event{
	int i,x;
	Event(int i,int x):i(i),x(x){}
	bool operator<(Event r)const{
		return x<r.x;
	}
};

struct Step{
	int i;
	int a,b;
	int dist;
	Step(){}
	Step(int i,int a,int b):i(i),a(a),b(b){
		dist = a<=b?b-a:m-a+b;
	}
	bool operator<(Step r)const{
		return b<r.b;
	}
	vc<Event> getEvents(){
		vc<Event> r;
		if(1+b-dist>=0) r.pb(Event(i,1+b-dist));
		r.pb(Event(i,b+1));
		r.pb(Event(i,m-dist+b+1));
		return r;
	}
	Linfun cost(int x){
		return 1+b-dist <= x && x<b+1 ? Linfun(-1,1+b) : m-dist+b+1 <= x ? Linfun(-1,1+m+b) : Linfun(0,dist);
	}
};

main(){
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n>>m;
	vc<int> a(n);
	f(i,n) cin>>a[i],a[i]--;
	vc<Step> steps(n-1);
	f(i,n-1) steps[i]=Step(i,a[i],a[i+1]);
	vc<Event> events;
	f(i,n-1) for(auto e:steps[i].getEvents()) events.pb(e);
	sort(all(events));
	auto lf=Linfun(0,0);
	f(i,n-1) lf+=steps[i].cost(0);
	int j=0;
	while(events[j].x==0) j++;
	int best=2e18;
	f(x,m){
		for(;j<sz(events)&&events[j].x==x;j++){
			int i=events[j].i;
			lf-=steps[i].cost(x-1);
			lf+=steps[i].cost(x);
		}
		int cand=lf.eval(x);
		if(cand<best) best=cand;
	}
	cout<<best<<'\n';
}


Measured memory_bytes: 10224
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
int main(){
	string s;
	cin>>s;
	int co=0;
	rep(i,s.size())if(s[i]=='+')co++;
	else co--;
	cout<<co<<endl;
}







Measured memory_bytes: 256
n = gets.to_i
nums = gets.split.map(&:to_i).sort
a = nums.last
a_half = a / 2.0
b_1_i = nums.bsearch_index { |num| num >= a_half }
b_2_i = b_1_i - 1
b = (nums[b_1_i] - a_half).abs < (nums[b_2_i] - a_half).abs ? nums[b_1_i] : nums[b_2_i]
puts "#{a} #{b}"


Measured memory_bytes: 10112
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
counter_a = Counter(a)
ok_list = []
for key,value in counter_a.items():
    if value >= 4:
        ok_list.append(key)
        ok_list.append(key)
    elif value >= 2:
        ok_list.append(key)
    else:
        continue
ok_list.sort(reverse=True)
if len(ok_list) >= 2:
    ans = ok_list[0] * ok_list[1]
else:
    ans = 0
print(ans)

Measured memory_bytes: 22168
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools
import heapq
#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


def main():

    s,w=map(int,input().split())
    ans="unsafe"
    if s>w:
        ans="safe"
    print(ans)



if __name__ == "__main__":

    main()

Measured memory_bytes: 68156
from collections import defaultdict
N, W, H = map(int, input().split())

*p, = range(N)
def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y
def unite(x, y):
    px = root(x); py = root(y)
    if px < py:
        p[py] = px
    else:
        p[px] = py

X = defaultdict(list)
Y = defaultdict(list)
for i in range(N):
    x, y = map(int, input().split())
    X[x].append(i)
    Y[y].append(i)

for x, vs in X.items():
    prv = vs[0]
    for v in vs[1:]:
        unite(prv, v)
        prv = v
for y, vs in Y.items():
    prv = vs[0]
    for v in vs[1:]:
        unite(prv, v)
        prv = v

cnt = 0
for i in range(N):
    pt = root(i)
    if pt == i:
        cnt += 1
ans = N-cnt + 2*(cnt-1)
if cnt > 1 and 1 not in X and W not in X and 1 not in Y and H not in Y:
    ans += 1
print(ans)



Measured memory_bytes: 19888
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())

if N % 10 in [2, 4, 5, 7, 9]:
    print("hon")
elif N % 10 == 3:
    print("bon")
else:
    print("pon")

Measured memory_bytes: 9520
/*	author:  Kite_kuma
	created: 2020.09.09 11:36:34 */

#include <iostream>
using namespace std;

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int res;
int a[200000], b[200000];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) cin >> b[i];
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++) res ^= a[i] + b[j];
	cout << res << "\n";
}

Measured memory_bytes: 5168
N = int(input())
A = sorted(list(map(int, input().split())))

if N == 1:
    print(1)
    exit()
    
check_list = [0] * (10**6 + 1)

cnt = 0
for i in range(len(A)):
    tmp = A[i]
    while True:
        if tmp > A[-1]:
            break
        check_list[tmp] += 1
        tmp += A[i]

for a in A:
    if check_list[a] == 1:
        cnt += 1
print(cnt)

Measured memory_bytes: 114064
#include<cstdio>

int main()
{
    int array[5];

    for (int i=0;i<5;i++)
    {
        scanf("%d", &array[i]);
    }
    if (   (array[2]-array[4])<0 
        || (array[2]+array[4])>array[0]
        || (array[3]-array[4])<0
        || (array[3]+array[4])>array[1]
       )
       {
            printf("No\n");
       }
    else
    {
        printf("Yes\n");
    }
}

Measured memory_bytes: 2696
package main

import (
	"fmt"
)

func main() {
	var N, Y int
	var exist bool
	var kumi = make(map[string]int)

	fmt.Scan(&N)
	fmt.Scan(&Y)

	max_a := Y / 10000
	if max_a > N {
		max_a = N
	}
	max_b := Y / 5000
	if max_b > N {
		max_b = N
	}
	
	for a := max_a; a >= 0 && !exist; a-- {
		for b := max_b-a; b >= 0 && !exist; b-- {
			c := N - a - b
			if c >=0 && a * 10000 + b * 5000 + c * 1000 == Y {
				exist = true
				kumi["a"] = a
				kumi["b"] = b
				kumi["c"] = c
				break;
			}
		}
	}

	if ! exist {
		kumi["a"] = -1
		kumi["b"] = -1
		kumi["c"] = -1
	}

	fmt.Printf("%d %d %d", kumi["a"], kumi["b"], kumi["c"])
}

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

int main()
{
  ll n,k;
  cin>>n>>k;
  ll a[n],j=0;
  for(ll i=0;i<n;i++)
  {
    cin>>a[i];
  }
  for(ll i=k;i<n;i++)
  {
    if(a[j]<a[i])
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
    j++;
  }
}

Measured memory_bytes: 5128
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>
#include<cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define rep(i,n) FOR(i,0,n)

struct edge{int to,cost;};

void dump_line(int *b,int n){
	for(int i=0;i<n;i++){
		cout << b[i] << " ";
	}
	cout << "\n";
}

ll mypow(ll x,ll n){
	if(n==0) return 1;
	ll res=mypow(x*x,n/2);
	if(n&1) res=res*x;
	return res;
}

ll mod_pow(ll x,ll n,ll mod){
	if(n==0) return 1;
	ll res=mod_pow(x*x%mod,n/2,mod);
	if(n&1) res=res*x%mod;
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	int a[n];
	int sum=0;
	rep(i,n){
		cin >> a[i];
		sum+=a[i];
	}
	int ans;
	int mindif=INF;
	rep(i,n){
		if(abs(a[i]*n - sum) < mindif){
			mindif = abs(a[i]*n - sum);
			ans = i;
		}
	}
	cout << ans << "\n";	

	return 0;
}

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

int n,cnt,answer;
string s;

int main() 
{
    cin>>n;
    cin>>s;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='W')
        {
            cnt++;
        }
    }
    for(int i=n-cnt;i<n;i++)
    {
        if(s[i]!='W')
        {
            answer++;
        }
    }
    cout<<answer<<endl;
    return 0;
}

Measured memory_bytes: 3728
n,m = map(int,input().split())
s_input = [[] for i in range(m)]
k_input = [0]*m

for i in range(m):
    k_input[i],*s_input[i] = map(int,input().split())
p_input = list(map(int,input().split()))

#全探索？スイッチのonoffでビット全探索したときに条件と一致するかひとつづつ
ans=0
for i in range(2**n):
    flag = True
    switch = [0]*n
    for j in range(n):
        if ((i>>j)&1):
            switch[j]=1
    for k in range(m):
        tmp=0
        for s in s_input[k]:
            tmp+=switch[s-1]
        if tmp%2!=p_input[k]:
            flag=False
            break
    if flag:
        ans+=1
print(ans)


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

int main() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ans += 2 * min(x, k - x);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
 
int main()
{
	ll N,M;
	cin >> N >> M;
	if (N == 1 && M == 1) cout << 1 << endl;
	else if(N == 1 || M == 1) cout << max(N,M)-2 << endl;
	else cout << (N-2) * (M-2) << endl;
	return 0;
}

Measured memory_bytes: 3556
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main() {
	int ans = 0;
	for (string s; cin >> s; ) {
		int num = 0;
		rep(i, s.size()) {
			if(isdigit(s[i])) num = num * 10 + s[i] -'0';
			else {
				if (num) ans += num;
				num = 0;
			}
		}
		if (num) ans += num;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 0