akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(){
    int s[8][8];
    int tmp;
    string str;
    do{
        for(int i=0; i<8; i++){
            cin >> tmp;
            for(int j=7; j>=0; j--){
                s[i][j] = tmp % 10;
                tmp /= 10;
            }
        }
        for(int i=0; i<8; i++){
            for(int j=0; j<8; j++){
                if(s[i][j] == 1){
                    if(s[i][j+1] == 1 && s[i+1][j] == 1 && s[i+1][j+1] == 1) cout << "A" << endl;
                    if(s[i+1][j] == 1 && s[i+2][j] == 1 && s[i+3][j] == 1) cout << "B" << endl;
                    if(s[i][j+1] == 1 && s[i][j+2] == 1 && s[i][j+3] == 1) cout << "C" << endl;
                    if(s[i+1][j] == 1 && s[i+1][j-1] == 1 && s[i+2][j-1] == 1) cout << "D" << endl;
                    if(s[i][j+1] == 1 && s[i+1][j+1] == 1 && s[i+1][j+2] == 1) cout << "E" << endl;
                    if(s[i+1][j] == 1 && s[i+1][j+1] == 1 && s[i+2][j+1] == 1) cout << "F" << endl;
                    if(s[i][j+1] == 1 && s[i+1][j] == 1 && s[i+1][j-1] == 1) cout << "G" << endl;
                }
            }
        }
    }while(getline(cin, str));
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  int counter = 700;
  if (S[0] == 'o') counter += 100;
  if (S[1] == 'o') counter += 100;
  if (S[2] == 'o') counter += 100;

  cout << counter << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<ctime>
using namespace std;
typedef long long lt;
typedef double dd;
#define eps 1e-6
#define sqr(x) ((x)*(x))

int read()
{
    int f=1,x=0;
    char ss=getchar();
    while(ss<'0'||ss>'9'){if(ss=='-')f=-1;ss=getchar();}
    while(ss>='0'&&ss<='9'){x=x*10+ss-'0';ss=getchar();}
    return f*x;
}

const int maxn=1000010;
int n;
struct point{dd x,y;}p[maxn],O;
dd R;

dd getd(point a,point b){ return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));}
point getO(point p1,point p2,point p3)
{
    point res;
    dd a=p2.x-p1.x,b=p2.y-p1.y,c=p3.x-p2.x,d=p3.y-p2.y;
    dd e=sqr(p2.x)+sqr(p2.y)-sqr(p1.x)-sqr(p1.y);
    dd f=sqr(p3.x)+sqr(p3.y)-sqr(p2.x)-sqr(p2.y);
    res.x=(f*b-e*d)/(c*b-a*d)/2.0;
    res.y=(a*f-e*c)/(a*d-b*c)/2.0;
    return res;
}

void mincir()
{
    O=p[1]; R=0;
    for(int i=1;i<=n;++i)
    if(getd(p[i],O)-R>eps)
    {
        O=p[i]; R=0;
        for(int j=1;j<i;j++)
        if(getd(p[j],O)-R>eps)
        {
            O=(point){(p[i].x+p[j].x)/2.0,(p[i].y+p[j].y)/2.0};
            R=getd(p[i],p[j])/2.0;

            for(int k=1;k<j;++k)
            if(getd(p[k],O)-R>eps)
            {
                O=getO(p[i],p[j],p[k]);
                R=getd(p[i],O);
            }
        }
    }
}

int main()
{
    n=read();
    for(int i=1;i<=n;++i)
    scanf("%lf%lf",&p[i].x,&p[i].y);

    random_shuffle(p+1,p+1+n);

    mincir();
    printf("%.10f",R);
    return 0;
}


Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
x=int(input())

n=0

for i in range(1,a+2):
  for k in range(1,b+2):
    for j in range(1,c+2):
      if (i-1)*500+(k-1)*100+(j-1)*50==x:
        n+=1

print(n)

Measured memory_bytes: 3060
n,m=map(int, input().split())
a= [list(map(int,input().split())) for i in range(n)]
for i in range(n):
    del a[i][0]
v=[]

x=0
for i in range(1,m+1):
    for j in range(n):
        v.append(a[j].count(i))

for i in range(0,m*n,n):
  
    if v[i:i+n].count(1)==n:
        x+=1

  
print(x)

Measured memory_bytes: 3064
#include <cstdio>
#include <set>
#define mp make_pair
#define FR first
#define SE second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=100010;
int n;
int a[N][2];
set<pii> l,r;
inline ll max(ll x,ll y){
	return x>y?x:y;
}
void readData(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i][0],&a[i][1]);
	a[n+1][0]=0; a[n+1][1]=0;
}
void addseg(int i){
	l.insert(mp(a[i][0],i));
	r.insert(mp(a[i][1],i));
}
void remseg(int i){
	l.erase(l.find(mp(a[i][0],i)));
	r.erase(r.find(mp(a[i][1],i)));
}
void initSet(){
	for(int i=1;i<=n;i++)
		addseg(i);
}
void move(int &cur,ll &sum,int t){
	if(a[t][0]<=cur&&cur<=a[t][1])
		return;
	else if(cur<a[t][0]){
		sum+=a[t][0]-cur;
		cur=a[t][0];
	}
	else{
		sum+=cur-a[t][1];
		cur=a[t][1];
	}
}
void goleft(int &cur,ll &sum){
	static set<pii>::iterator it;
	it=r.begin();	
	int id=(*it).SE;
	move(cur,sum,id);
	remseg(id);
}
void goright(int &cur,ll &sum){
	static set<pii>::iterator it;
	it=l.end();
	it--;
	int id=(*it).SE;
	move(cur,sum,id);
	remseg(id);
}
ll solve(int f){
	ll res=0;
	int cur=0;
	initSet();
	for(int i=1;i<=n;i++)
		if(i&1^f)
			goleft(cur,res);
		else
			goright(cur,res);
	move(cur,res,n+1);
	return res;
}
int main(){
	readData();
	printf("%lld\n",max(solve(0),solve(1)));
	return 0;
}

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;

int main()
{
	scanf("%d",&N);
	vector<int> A(N);
	set<int> st;
	int cnt = 0;
	FOR(i,0,N){
		scanf("%d",&A [i]);
		if(A [i] >= 3200){
			cnt++;
		}
		else{
			st.insert(A [i] / 400);
		}
	}

	int mn = max(1,int(st.size())),mx = max(1,cnt + int(st.size()));
	printf("%d %d\n",mn,mx);

	return 0;
}


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

int keta_sum(int x){
  
  int sum = 0; //各桁の和
  
  while(true){
    int r = x%10;
    sum += r;
    x = x/10;
    if(x == 0) break;
  }
  
  return sum;
  
}

int main() {
  int N,A,B;
  cin >> N >> A >> B;
  int ans = 0;
  
  for(int i = 1;i<=N;i++){
    if(keta_sum(i) >= A && keta_sum(i) <= B) ans += i;
  }

  cout << ans << endl;
  
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
    temp_list = list([a[i - 1], a[i], a[i + 1]])
    temp_list.sort()
    if temp_list[1] == a[i]:
        ans += 1
print(ans)

Measured memory_bytes: 3060
/*
01背包，1维实现
*/
#include<cstdio>
#include<algorithm>
#define MAXN 105
#define MAXW 100005
int w[MAXN], v[MAXN];
long long dp[MAXW];
int n, c;
int main(){
    scanf("%d%d", &n, &c);
    for(int i = 1; i <= n; i++)
        scanf("%d%d", &w[i], &v[i]);
    for(int i = 1; i <= n; i++)
        for(int j = c; j >= w[i]; j--)
            dp[j] = std::max(dp[j], dp[j-w[i]]+v[i]);
    printf("%lld\n", dp[c]);
}
 

Measured memory_bytes: 896
n,m = map(int,input().split())
left = 1
right = n

for i in range(m):
    l,r = map(int,input().split())
    if l > left:
        left = l
    if r < right:
        right = r

if left > right:
    print(0)
else:
    print(right - left + 1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef vector<int8_t> vcc;
typedef vector<vcc> vvcc;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll h, w;
        in >> h >> w;
        vvcc p(h, vcc(w));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                in >> p[i][j];
            }
        }
        for (int i = 0; i < 2 * h; i++) {
            for (int j = 0; j < w; j++) {
                out << p[i / 2][j];
            }
            out << '\n';
        }
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
  lint N,K;
  cin >> N >> K;
  lint A[N];
  rep(i,N) cin >> A[i];
  lint ans=0;
  lint range=accumulate(A,A+K,0LL);
  lint other=0;
  for(int i=K;i<N;i++) if(A[i]>0) other+=A[i];
  ans=max(0LL,range)+other;
  for(int i=K;i<N;i++){
    range+=A[i]-A[i-K];
    if(A[i-K]>0) other+=A[i-K];
    if(A[i]>0) other-=A[i];
    ans=max(ans,max(0LL,range)+other);
  }
  cout << ans << endl;
}

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

int main(){
    int X,A,B;
    cin >> X >> A >> B;
    if(A>=B){
        cout << "delicious" << endl;
    }else{
        if(A+X>=B){
            cout << "safe" << endl;
        }else{
            cout << "dangerous" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,i,c=0;
cin>>n;
for(i=1;i<=9;i++){

    if((n%i==0)&&(n/i<=9))
    {
        c=c+1;

        break;
    }
    else
        continue;

}
if(c==0)
        cout<<"No"<<endl;
else
        cout<<"Yes"<<endl;


return 0;

}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int r,c;
    int i,j;
    scanf("%d %d",&r,&c);//r:???c:?¨????r???c???
    int array[101][101]={0};
    for(j=0;j<r;j++){//????????????
        for(i=0;i<c;i++){//?¨??????????
            scanf("%d",&array[i][j]);
            array[c][j]+=array[i][j];
            array[i][r]+=array[i][j];
            array[c][r]+=array[i][j];
            
        }
    }for(j=0;j<=r;j++){
        if(j!=0){
            printf("\n");
        }
        for(i=0;i<=c;i++){
            if(i!=0){
                printf(" ");
            }
            printf("%d",array[i][j]);
                    }
    }printf("\n");
    return 0;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    int Min = INF;

    for (int i = -100; i <= 100; i++) {
        int sum = 0;

        rep(k, n) {
            sum += (a[k] - i)*(a[k] - i);
        }
        Min = min(Min, sum);
    }

    cout << Min << endl;
    return 0;
}



Measured memory_bytes: 256
def main():
    n = int(input())
    t, a = map(int, input().split())
    h = list(map(int, input().split()))

    ans, mn = 0, abs(t-h[0]*0.006-a)
    for i in range(n):
        ai = t - h[i] * 0.006
        if abs(ai-a) < mn:
            ans = i
            mn = abs(ai-a)

    print(ans+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h> 
using namespace std;
const long long p=1000000007ll;
long long n,k,f[10001];
long long qq(long long a,int x)
{
	if(x<0) return 1;
	long long s=1ll;
	while(x) {if(x&1)(s*=a)%=p;(a*=a)%=p;x>>=1;}
	return s;
}
int main()
{
    scanf("%lld%lld",&n,&k);
    f[0]=1ll;
    for(int i=1;i<n;++i) {for(int j=i;j;j--)f[j]=(f[j+1]+f[j-1])%p;f[0]=f[1];}
    printf("%lld",f[n-k]*qq(2ll,n-k-1)%p);
    return 0;
}

Measured memory_bytes: 256
using System;

public class AtCoderC
{
    static void Main()
    {
        int n;
        int k;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            n = int.Parse(words[0]);
            k = int.Parse(words[1]);
        }

        decimal answer = 0;
        for (int i = 1; i <= n; i++)
        {
            decimal expect = 1;
            int score = i;
            while (true)
            {
                if (score >= k)
                {
                    break;
                }
                score *= 2;
                expect /= 2;
            }
            answer += expect / n;
        }

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 13140
import math
import collections
import sys

#input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]

d=I()
print("Christmas" ,end=" ")
for i in range(25-d):
    print("Eve",end=" ")

Measured memory_bytes: 3316
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll sum;
int a[2],n,p;

ll ir[60][60];


void Fir()
{
	ir[1][0]=1;
	ir[1][1]=1;
	ir[0][0]=1;
	for(int i=2;i<=55;i++) ir[i][0]=1;
	for(int i=2;i<=55;i++)
		for(int j=1;j<=i;j++)
			ir[i][j]=ir[i-1][j-1]+ir[i-1][j];	
		
}

ll C(int n,int m){return ir[n][m];}

int main()
{
   	Fir();
	scanf("%d%d",&n,&p);
	for(int i=0;i<n;i++)
	{
		int x;
		scanf("%d",&x);
		a[x%2]++;
	}
	if (!p%2) sum++;

	if (p%2 )sum+=(ll)a[1];
	else sum+=(ll)a[0];
	for(int i=2;i<=n;i++)	
		for(int j=0;j<=i;j++)
		{
			int k=i-j;
			if (j>a[0]||k>a[1])
				continue;
	
			if ((j*0+k*1)%2==p)
				sum+=C(a[0],j)*C(a[1],k);
				
				
		}
		

		
	printf("%lld\n",sum);
				
	return 0;
}

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

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a * n, b) << endl;
	return 0;
}


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

const int N=2e5+20,MAX=1e6+20;

int n,x,f[MAX];
bool ok[MAX];

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&x),f[x]++;
	for(int i=1;i<MAX;i++) ok[i]=true;

	for(int i=1;i<MAX;i++)
		if(f[i])
			for(int j=2*i;j<MAX;j+=i)
				ok[j]=false;
	int ans=0;
	for(int i=1;i<MAX;i++)
		if(ok[i] and f[i]==1) ans++;
	printf("%d",ans);
}

Measured memory_bytes: 8708
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<string>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define p(s) cout << (s) << endl
#define p2(s,t) cout << (s) << " " << (t) << endl 
#define ALL(v) (v).begin(), (v).end()
typedef long long ll;
using namespace std;

static const ll mod  = 1e9 + 7;
static const ll inf  = 1e18;

static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

void pvector(vector<ll> A){
    cout << "[vector]";
    for(int i = 0; i < A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b){
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first > b.first;
    }
} 

int main(){
    int n, m, t;
    ll b, c;
    ll ans = 0;
    cin >>n >> m;
    vector<ll> a;
    vector<pair<ll, ll> > pairs;
    REP(i, n){
        cin >> t;
        a.push_back(t);
    }
    sort(ALL(a));
    REP(i, m){
        cin >> b >> c;
        pairs.push_back(make_pair(b,c));
    }
    /*cout << "[vector]";
    for(int i = 0; i < pairs.size(); i++){
        cout << pairs[i].first << " " << pairs[i].second << endl;
    }*/
    sort(ALL(pairs), compare_by_b);
    int point = 0;
    bool flag = 0;
    int j = 0;
    while(point < a.size() && j < pairs.size()){
        int tmpp = point;
        for(int i = point; i < tmpp + pairs[j].first; i++){
            if(pairs[j].second > a[i]){
                a[i] = pairs[j].second;
                point++;
            }else{
                flag = 1;
                break;
            }
        }
        j++;
        if(flag) break;
    }
    /*cout << "[vector]";
    for(int i = 0; i < pairs.size(); i++){
        cout << pairs[i].first << " " << pairs[i].second << endl;
    }
    pvector(a);
*/
    REP(i,n){
        ans += a[i];
    }
    p(ans);

}

Measured memory_bytes: 3188
'''
def factorial(n):
    if n == 1:
        return n
    return n*factorial(n-1)
'''
n = int(input())
xy = [list(map(int,list(input().split()))) for i in range(n)]

sum = 0
for ida in range(n):
    for idb in range(n):
        if ida == idb: continue
        sum += ((xy[ida][0]-xy[idb][0])**2+(xy[ida][1]-xy[idb][1])**2)**0.5

ans = sum / n

print(ans)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    int end = m / n;
    int ans = 1;
    vector<int> v;
    for (int i = 1; i * i <= m && i <= end; i++)
    {
        if(m%i == 0){
            v.push_back(i);
            if(m/i<=end){
                v.push_back(m / i);
            }
        }
    }
    for (auto e : v){
        int tmp = m - (n - 1) * e;
            if(tmp % e ==0){
                ans = max(ans,e);
            }
    }
    cout << ans << endl;
}



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

namespace Sample
{
	class Program
	{
		static void Main(string[] args)
		{
			var array = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
			var a = array[0];
			var b = array[1];
			var area = a * b;
			var len = 2 * (a + b);

			Console.WriteLine($"{area} {len}");
		}
	}
}



Measured memory_bytes: 18164
function Main(input) {
  var N = parseInt(input.split("\n")[0]);
  var K = parseInt(input.split("\n")[1]);
  var number = 1;
  for(var i = 0; i < N; i++){
    if((number * 2 -  number) <= K){
       number = number * 2;
    }else{
      number += K;
    }
    
  }
  console.log(number);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b)" (((a%MOD+MOD)%MOD+(b%MOD+MOD)%MOD)%MOD)
#define SUB(a, b) (((a%MOD+MOD)%MOD-(b%MOD+MOD)%MOD+MOD)%MOD)
#define MUL(a, b) ((((a%MOD+MOD)%MOD)*((b%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) (x/gcd(x,y)*y)
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }
template<typename I> int ACC(I f, I l, int i = 0){ return accumulate(f, l, i); }


int N;
int iP[100010];
multiset<int> ms;


signed main(){
    cin >> N;
    repe(i, 1, N){
        int P;
        cin >> P;
        iP[P] = i;
    }

    int ans = 0;
    ms.insert(0);
    ms.insert(0);
    ms.insert(N+1);
    ms.insert(N+1);
    ms.insert(iP[N]);
    repr(i, N, 1){
        int x[4];
        auto pos = ms.lb(iP[i]);
        pos--;pos--;
        rep(i, 0, 4) x[i] = *pos, pos++;
        int c = (x[1]-x[0])*(x[2]-iP[i])+(x[3]-x[2])*(iP[i]-x[1]);
        ans += i*c;
        ms.insert(iP[i]);
    }

    cout << ans << endl;

    return 0;
}

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

const int MAXN = 100 * 1000 + 100;
vector <int> adj[MAXN];
bool p = true;
int good[MAXN], mark[MAXN], cnt[3];


void dfs(int v, bool b) {
	mark[v] = true;
	good[v] = b;
	for(int i : adj[v]) {
		if(!mark[i])
			dfs(i, !b);
		else if(good[i] == good[v])
			p = false;
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for (int i = 0; i < n; i++)
		if (!mark[i]) {
			if (!adj[i].size()) {
				cnt[2]++;
				continue;
			}
			p = true;
			dfs(i, 0);
			cnt[p]++;
		}
	cerr << cnt[0] << ' ' << cnt[1] << ' ' << cnt[2] << endl;
	ll ans = (ll)cnt[1] * cnt[1] * 2 + (ll)cnt[0] * cnt[1] * 2;
//	cerr << ans << endl;
	ans += (ll)cnt[2] * n * 2 - (ll)cnt[2] * cnt[2];
//	cerr << ans << endl;
	ans += cnt[0] * cnt[0] * 2 - cnt[0] * cnt[0];
	cout << ans << endl;
}


Measured memory_bytes: 10368
n = int(input().split()[0])
c = list(filter(lambda x:x <= n,map(int,input().split())))
m = len(c)

minimum = [n] * (n+1)
minimum[0] = 0
for i in c:
    minimum[i] = 1

for i in range(1,n+1):
    for j in range(m):
        if c[j]<=i and minimum[i-c[j]] + 1 < minimum[i]:
            minimum[i] = minimum[i-c[j]]+1

print(minimum[n])

Measured memory_bytes: 9168
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
struct P{
    int a, b, c;
    P(int x, int y, int z){
        a = x; b = y; c = z;
    }
    bool operator<(const P &x)const{
        return a-b < x.a-x. b;
    };
};
int main(void){
    int x, y, z;
    long long ans = 0, left[100000], right[100000];
    vector<P> v;
    priority_queue<int> q;
    cin >> x >> y >> z;
    for(int i=0;i<x+y+z;i++){
        int a, b, c;
        cin >> a >> b >> c;
        v.push_back(P(a, b, c));
    }
    sort(v.begin(), v.end());
    left[0] = 0;
    for(int i=0;i<y;i++){
        left[0] += v[i].b;
        q.push(v[i].c-v[i].b);
    }
    for(int i=1;i<=z;i++){
        int t = y-1+i;
        left[i] = left[i-1] + v[t].b;
        q.push(v[t].c - v[t].b);
        left[i] += q.top();
        q.pop();
    }
    while(!q.empty())q.pop();
    right[0] = 0;
    for(int i=y+z;i<x+y+z;i++){
        right[0] += v[i].a;
        q.push(v[i].c-v[i].a);
    }
    for(int i=1;i<=z;i++){
        int t = y+z-i;
        right[i] = right[i-1] + v[t].a;
        q.push(v[t].c - v[t].a);
        right[i] += q.top();
        q.pop();
    }
    for(int i=0;i<=z;i++){
        ans = max(ans, left[i] + right[z-i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 2676
var
    a,b,c,d,min,n:int64;
begin
    read(a,b,c,d,n);
    min:=a*4;
    if b*2<min then min:=b*2;
    if c<min then min:=c;
    if min*2>d then
    begin 
        if n mod 2=0 then writeln(n div 2*d)
        else writeln(n div 2*d+min);
    end
    else writeln(n*min);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

int main(){
    
    int a;
    string s;cin>>a>>s;
    if(a>=3200) cout<<s<<endl;
    else cout<<"red"<<endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll; 
using namespace std;
int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0;i < n;i++) cin >> a[i];
    
    ll q;
    cin >> q;
    
    for(ll i = 0;i < q;i++){
        ll x;
        cin >> x;
        
      if(binary_search(a.begin(), a.end(), x)) cout << 1 << endl;
      else cout << 0 << endl;
        
    }
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>

#define MAX_LENGTH 10001

int main(void) 
{
	char str[MAX_LENGTH], *target;
	int JOI, IOI;

	while (scanf("%s", str) != EOF) {
		JOI = IOI = 0;
		target = str;

		while ((target = strstr(target, "JOI")) != NULL) {	   
			JOI++;
			target++;
		}

		target = str;

		while ((target = strstr(target, "IOI")) != NULL) {		
			IOI++;
			target++;
		}
	
		printf("%d\n", JOI);
		printf("%d\n", IOI);
	}
	return 0;
}

Measured memory_bytes: 560
#include <stdio.h>

double err(int t, int x, int a){
	double temp = (double)t - 0.006 * x;
	if(a < temp)
		return temp - (double)a;
	else
		return (double)a - temp;
}

int main(){
	int n, t, a, in, min;
	double mine = 1e10;

	scanf("%d", &n);
	scanf("%d %d", &t, &a);

	for(int i = 0; i < n; i++){
		scanf("%d", &in);
		if(err(t, in, a) < mine){
			min = i + 1;
			mine = err(t, in, a);
		}
		//printf("%f\n", err(t, in, a));
	}
	printf("%d\n", min);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n;
	while( cin >> n , n ){
		vector<int> p1, p2;
		int field = 0;
		
		for(int i=0 ; i < n ; i++ ){
			int a;
			cin >> a;
			p1.push_back( a );
		}
		sort( p1.begin() , p1.end() );
		for(int i=1 ; i <= 2*n ; i++ ){
			if( count( p1.begin() , p1.end() , i ) == 0 ){
				p2.push_back( i );
			}
		}
		
		bool p1_flag = true, p2_flag = true;
		while( p1_flag || p2_flag ){
			p1_flag = false;
			p2_flag = false;
			for(int i=0 ; i < p1.size() ; i++ ){
				if( field < p1[i] ){
					field = p1[i];
					p1_flag = true;
					p1.erase( remove( p1.begin() , p1.end() , p1[i] ) , p1.end() );
					break;
				}
			}
			if( p1_flag == false ){
				field = 0;
			}
			if( p1.empty() ) break;
			
			for(int i=0 ; i < p2.size() ; i++ ){
				if( field < p2[i] ){
					field = p2[i];
					p2_flag = true;
					p2.erase( remove( p2.begin() , p2.end() , p2[i] ) , p2.end() );
					break;
				}
			}
			if( p2_flag == false ){
				field = 0;
			}
			if( p2.empty() ) break;
		}
		cout << p2.size() << endl;
		cout << p1.size() << endl;
	}
}

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

int prime(int num){
    if(num%2 == 0) return 0;
    for(int i=1;i<num/2;i++){
        if(num%(i*2+1)==0) return 0;
    }
    return 1;
}

int main(){
    int x;
    cin >> x;
    if(x==2){
        cout << x << endl;
        return 0;
    }
    for(int i=x; i<=INT_MAX;i++){
        int ans = prime(i);
        if(ans==1){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int k,n; cin >> n >> k;
  vector<int> cnt(n,0);
  rep(i,k){
    int d; cin >> d;
    rep(j,d){
      int a; cin >> a;
      a--;
      cnt[a]++;
    }
  }
  int ans=0;
  rep(i,n) if(cnt[i]==0) ans++;
  cout << ans << endl;
  return 0;
}


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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
    int n;
    cin >> n;
    int nt=0,nx=0,ny=0;
    for(int i=0;i<n;i++){
        int t,x,y;
        cin >> t >> x >> y;
        int d=abs(x-nx)+abs(y-ny);
        if(d>t-nt){
            cout << "No" << endl;
            return;
        }
        if(d%2==(t-nt)%2){
            nt=t;
            nx=x;
            ny=y;
        }
        else {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
    
}

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static final int MOD = 1000000007;
	static int N, total;
	static long[] pow10 = new long[801];
	static long[] fact = new long[201];
	static long[][] binom = new long[201][201];

	public static void main(String[] args) {
		pow10[0] = fact[0] = 1;
		for (int i = 1; i < pow10.length; ++i) {
			pow10[i] = pow10[i - 1] * 10 % MOD;
		}
		for (int i = 1; i < fact.length; ++i) {
			fact[i] = fact[i - 1] * i % MOD;
		}
		for (int i = 0; i <= 200; ++i) {
			binom[i][i] = binom[i][0] = 1;
		}
		for (int i = 0; i <= 200; ++i) {
			for (int j = 1; j < i; ++j) {
				binom[i][j] = (binom[i - 1][j] + binom[i - 1][j - 1]) % MOD;
			}
		}
		N = sc.nextInt();
		int[] A = new int[N];
		int zi = -1;
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
			if (A[i] == 0) zi = i;
		}
		int ans = solve(A);
		if (zi != -1) {
			int[] B = new int[N - 1];
			int idx = 0;
			for (int i = 0; i < N; ++i) {
				if (i == zi) continue;
				B[idx++] = A[i];
			}
			ans += MOD - solve(B);
			ans %= MOD;
		}
		System.out.println(ans);
	}

	static int solve(int[] A) {
		int[] digits = new int[5];
		for (int i = 0; i < A.length; ++i) {
			digits[(A[i] + "").length()]++;
		}
		total = digits[1] + digits[2] * 2 + digits[3] * 3 + digits[4] * 4;
		int[][][] comb = new int[5][][];
		for (int i = 1; i <= 4; ++i) {
			if (digits[i] > 0) {
				comb[i] = calcComb(digits, i);
			}
		}
		long ret = 0;
		for (int i = 0; i < A.length; ++i) {
			int len = (A[i] + "").length();
			for (int j = 0; j < A.length; ++j) {
				long add = 0;
				for (int k = 0; k <= A.length - 1 - j; ++k) {
					add += binom[A.length - 1 - j][k] * fact[k];
					add %= MOD;
				}
				add *= A[i];
				add %= MOD;
				add *= fact[j];
				add %= MOD;
				for (int k = 0; k < total && k <= j * 4; ++k) {
					long addElem = add * pow10[k] % MOD;
					addElem *= comb[len][j][k];
					addElem %= MOD;
					ret += addElem;
				}
				ret %= MOD;
			}
		}
		return (int) ret;
	}

	static int[][] calcComb(int[] digits, int cur) {
		digits[cur]--;
		int[][] dp = new int[N][total + 1]; // dp[i][j] : j digits with i cards
		dp[0][0] = 1;
		int sum = 0;
		int idx = 0;
		for (int i = 1; i <= 4; ++i) {
			for (int j = 0; j < digits[i]; ++j, ++idx) {
				sum += i;
				for (int k = idx + 1; k > 0; --k) {
					for (int l = sum; l >= i; --l) {
						dp[k][l] += dp[k - 1][l - i];
						if (dp[k][l] >= MOD) dp[k][l] -= MOD;
					}
				}
			}
		}
		digits[cur]++;
		return dp;
	}
}

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

int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> a(n);
  for(int i=0;i<n;i++) cin >> a.at(i).second >> a.at(i).first;
  
  sort(a.begin(),a.end());
  
  int time=0;
  string s="Yes";
  
  for(int i=0;i<n;i++){
    time+=a.at(i).second;
    if(a.at(i).first<time){
      s="No";
      i=n;
    }
  }
  cout << s << endl;
}

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

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 59;
const int mod = 1e9 + 7;

int main() {
  int N, K;
  cin >> N >> K;
  vector< int > dp(K + 2);
  dp[0] = 1;
  for(int i = 0; i < N; i++) {
    vector< int > add_dp(K + 2);
    int x;
    cin >> x;
    for(int j = K; j >= 0; j--) {
      (add_dp[min(j + x + 1, K + 1)] += mod - dp[j]) %= mod;
      (add_dp[j] += dp[j]) %= mod;
    }
    for(int j = 1; j <= K; j++) {
      (add_dp[j] += add_dp[j - 1]) %= mod;
    }
    dp.swap(add_dp);
  }
  cout << dp[K] << endl;
}




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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

void solve() {

	string s, ans = "";
	cin >> s;
	
	for(char c: s) {
		if(c == '?') {
			ans += 'D';
		} else {
			ans += c;
		}
	}
	cout << ans << endl;
}
		
			
		

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


Measured memory_bytes: 3892
using System;
using System.Linq;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        Console.WriteLine(solve(long.Parse(Console.ReadLine())));
    }
    static int solve(long i)
    {
        string n = i.ToString();
        int res = 0;
        if (n.Length == 1)
        {
            res = n[0] - '0';
        }
        else if (n[0] != '9')
        {
            if (n.Count(x => x != '9') == 1)
            {
                res = 9 * (n.Length - 1) + (n[0] - '0');
            }
            else
            {
                res = 9 * (n.Length - 1) + (n[0] - '0' - 1);
            }
        }
        else if (n.Count(x => x != '9') != 0)
        {
            res = 9 * (n.Length - 1) + 8;
        }
        else
        {
            res = 9 * (n.Length - 1) + 9;
        }
        return res;
    }
}

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

int main() {
    int n;  cin >> n;
    long a[n];  for (int i = 0; i < n; i++) cin >> a[i];
  
    long sum = 0, xor_sum = 0, cnt = 0;  
    for (int l = 0, r = 0; l < n; l++) {
        while (r < n && sum + a[r] == (xor_sum ^ a[r])) {
            sum += a[r];  xor_sum ^= a[r];
            r++;
        }
        cnt += r - l;
        sum -= a[l];  xor_sum ^= a[l];
    }
  
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;

int A[1000000],n;

int main(){
	cin >> n;
	for(int i = 0;i < n;i++)
		scanf("%d",&A[i]);
		
	int q,k,sum = 0;
	cin >> q;
	for(int i = 0;i < q;i++){
		scanf("%d",&k);
		if(*lower_bound(A,A+n,k) == k)
			sum++;
	}
	
	cout << sum << endl;
	
	return 0;
}


Measured memory_bytes: 3420
n=int(input())
f=0
fn=0
for i in range(1,n+1): #1からnまで全探索
    c=0
    s=i
    while s%2==0: #2で割り切れるうちは割っていく cは割った回数
        s=s//2
        c+=1
    #割り切りおわった
    if c>=f:
        fn=i
        f=c
print(fn)

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

using i64 = int64_t;

int main(){
    int n, w;
    while(cin >> n >> w, n != 0){
        vector<int> v(105);
        int rightmost = 0, maxi = 0;
        for(int i=0;i<n;++i){
            int tmp;
            cin >> tmp;
            v[tmp/w]++;
            rightmost = max(rightmost, tmp/w);
            maxi = max(maxi,v[tmp/w]);
        }
        double ans = 0.01;
        for(int i=0;i<rightmost;++i){
            ans += v[i] * (rightmost-i)/(double)(maxi*rightmost);
        }
        printf("%.10f\n", ans);
    }

    return 0;
}



Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  ll x = n * a;
  chmin(x, b);
  print(x);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll qo(bool q){ return (q ? 0 : qo(q)); }

const int mnx = 1e6 + 9;
const int mod = 1e9 + 7;

int n, m;
int a[mnx], b[mnx];
vector<int> e[mnx];
vector<int> ans1, ans2;
bool used[mnx];

int ok(int x){
    for(int i = 0; i < e[x].size(); i++){
        if(!used[e[x][i]]) return e[x][i];
    }
    return -1;
}
 
int main(){
 
cin >> n >> m;

for(int i = 0; i < m; i++){
    cin >> a[i] >> b[i];
    e[a[i]].push_back(b[i]);
    e[b[i]].push_back(a[i]);
}
 
int x = a[0],y = b[0];
queue<int> q;
q.push(x);
used[x] = 1;
used[y] = 1;
ans1.push_back(x);

while(!q.empty()){
    x=q.front();
    q.pop();
    if(ok(x)==-1) break;
    q.push(ok(x));
    ans1.push_back(ok(x));
    used[ok(x)]=1;
}

queue<int> q2;
q2.push(y);
ans2.push_back(y);

while(!q2.empty()){
    y = q2.front();
    q2.pop();
    if(ok(y) == -1) break;
    q2.push(ok(y));
    ans2.push_back(ok(y));
    used[ok(y)] = 1;
}

cout << ans2.size() + ans1.size() << endl;

for(int i = ans2.size() - 1;i >= 0; i--){
    cout << ans2[i] << " ";
}

for(int i = 0; i < ans1.size(); i++){
    cout << ans1[i] << " ";
}

qo(true);

}

Measured memory_bytes: 34296
#include <stdio.h>

void insertionSort(int*, int, int);
void shellSort(int*, int);
void print(int, int*, int*, int);

int cnt;

int main(void){
  int n, i;
  int A[1000000];
  scanf("%d", &n);
  for(i = 0; i < n; i ++){
    scanf("%d", &A[i]);
  }
  shellSort(A, n);
  return 0;
}

void insertionSort(int *A, int n, int g){
  int i, j, v;
  for(i = g; i < n; i++){
    v = A[i];
    j = i - g;
    while((j >= 0)&&(A[j] > v)){
      A[j+g] = A[j];
      j -= g;
      cnt++;
    }
    A[j+g] = v;
  }
  return;
}

void shellSort(int *A, int n){
  int m, i, j, G[100];
  cnt = 0;
  for(i = 0; i < n; i++){
    G[i] = n/2;
    for(j = 0; j < i; j++){
      G[i] /= 2;
    }
    m++;
    if(G[i] == 0) G[i] = 1;
    if(G[i] == 1) break;
  }
  for(i = 0; i < m; i++){
    insertionSort(A, n, G[i]);
  }
  print(m, G, A, n);
  return;
}

void print(int m, int *G, int *A, int n){
  int i;
  printf("%d\n", m);
  for(i = 0; i < m; i++){
    printf("%d", G[i]);
    if(i+1 != m) printf(" ");
  }
  printf("\n%d\n", cnt);
  for(i = 0; i < n; i++){
    printf("%d\n", A[i]);
  }
  return;
}

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


int main(){
  int n;
  cin >> n;
  if(n>=64) cout << "64";
  else if (n>=32) cout << "32";
  else if(n>=16) cout << "16";
  else if(n>=8) cout << "8";
  else if(n>=4) cout << "4";
  else if(n>=2) cout << "2";
  else cout << "1";
  cout << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    long long n;
    cin >> n;

    vector<long long> a(n);
    vector<long long> b(n);
    vector<long long> c(n);

    for(long long i = 0; i < n; i++){
        cin >> a[i];
    }
    for(long long i = 0; i < n; i++){
        cin >> b[i];
    }
    for(long long i = 0; i < n; i++){
        cin >> c[i];
    }

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

    long long ans = 0;
    for(long long j = 0; j < n; j++){
        long long pivot = b[j];
        long long distance_a = lower_bound(a.begin(), a.end(), pivot) - a.begin();
        long long distance_c = c.end() - upper_bound(c.begin(), c.end(), pivot);
        ans += distance_a*distance_c;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	ll N; cin >> N;
	char s[100000];
	ll n[5] = {};
	rep(i, 0, N) {
		char c[11]; cin >> c;
		if (c[0] == 'M')n[0]++;
		else if (c[0] == 'A')n[1]++;
		else if (c[0] == 'R')n[2]++;
		else if (c[0] == 'C')n[3]++;
		else if (c[0] == 'H')n[4]++;
	}

	ll sum = 0;
	rep(i, 0, 5) {
		rep(j, i + 1, 5) {
			rep(k, j + 1, 5) {
				sum += n[i] * n[j] * n[k];
			}
		}
	}
	cout << sum << endl;

	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)
#define ll long long

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll c = a+b;
    ll d = n/c;
    ll e = n%c;
    ll f;
    if (a < e) f = a;
    else f = e;
    ll ans = a*d + f;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 100000000
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    cout << pow(2, floor(log2(n))) << '\n';
}

Measured memory_bytes: 256
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    n = int(input())
    if n%2 == 1:
        print(0)
        exit(0)
    
    def count(k, n):
        now = k
        cnt = 0
        while now <= n:
            cnt += n//now
            now *= k
        return cnt

    n //= 2
    cnt2 = n
    cnt2 += count(2, n)
    cnt5 = count(5, n)
    ans = min(cnt2, cnt5)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9100
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let mut X = read![i64];

    let a = X / 500;
    X -= a * 500;

    let b = X / 5;
    // X -= b * 5;

    println!("{}", a * 1000 + b * 5)
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <unistd.h>
#include <sstream>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846
#define pb push_back

int power(int a,int b)
{
    if(b==0)
        return 1;
    else if(b%2==0)
        return power((a%div*a%div)%div,b/2);
    else
        return (a%div*power((a%div*a%div)%div,(b-1)/2)%div)%div;
}

void solve()
{
    int n;cin>>n;
    if(n==1)
    {
        cout<<0;
        return;
    }
    int v1=power(10LL,n);
    int v2=power(9LL,n);
    int v3=power(8LL,n);
    v2=(2%div*v2%div)%div;
    int ans=(v1+v3)%div;
    ans=(ans%div+div-v2%div)%div;
    cout<<ans;
}

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

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define mii map<int, int>
#define mci map<char, int>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << "debug: " << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n) {
    int tmp;
    cin >> tmp;
    mp[tmp]++;
  }
  int ans = mp.begin()->se;
  if (abs(next(mp.begin(), 1)->fi - mp.begin()->fi) < 2)
    ans += next(mp.begin(), 1)->se;
  if (abs(mp.end()->fi - next(mp.end(), -1)->fi < 2))
    chmax(ans, mp.end()->se + next(mp.end(), -1)->se);
  for (auto i = mp.begin(); i != mp.end(); ++i) {
    if (i == mp.begin() || i == mp.end())
      continue;
    else if (abs(i->fi - next(i, -1)->fi) < 2 &&
             abs(i->fi - next(i, 1)->fi) < 2)
      chmax(ans, next(i, -1)->se + i->se + next(i, 1)->se);
  }
  out(ans);
}
int main(void) { solve(); }

Measured memory_bytes: 6404