akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#include <unordered_map>

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;

const double EPS = 1e-13;

struct BIT{
    int n;
    VL bit;

    BIT(){}
    BIT(int x){
        n = x;
        bit.resize(x+1);
    }

    void init(int x){
        n = x;
        bit.resize(x+1);
    }

    void add(int i, ll x){
        i++;
        while (i <= n){
            bit[i] += x;
            i += i & -i;
        }
    }

    // [0, i]
    ll sum(int i){
        i++;
        ll ret = 0;
        while (i > 0){
            ret += bit[i];
            i -= i & -i;
        }
        return ret;
    }

    // [l, r)
    ll sum(int l, int r){
        if (l >= r) return 0;
        return sum(r-1) - sum(l-1);
    }
};

// VI compress_coordinate(vector<double> x){
//     int n = x.size();
//     vector<pair<double, int> > p(n);
//     REP(i,n){
//         p[i].first = x[i];
//         p[i].second = i;
//     }
//     sort(ALL(p));
//     VI ret(n);
//     REP(i,n){
//         ret[p[i].second] = i;
//     }
//     return ret;
// }

VI compress_coordinate(VD x){
    int n = x.size();
    VD xc;
    REP(i,n) xc.push_back(x[i]);
    sort(ALL(xc));
    REP(i,n-1){
        if (xc[i+1] - xc[i] < EPS) xc[i+1] = xc[i];
    }
    xc.erase(unique(ALL(xc)), xc.end());
    VI ret(n);
    REP(i,n) ret[i] = lower_bound(ALL(xc), x[i] - EPS) - xc.begin();
    return ret;
}

double calc(VD a, VD b, VD c, ll k){
    int n = a.size();
    vector<pair<double, double> > line(n);
    REP(i,n){
        line[i].first =  - a[i] / b[i];
        line[i].second = c[i] / b[i];
    }
    sort(ALL(line));

    double le = -1e9, ri = 1e9;
    REP(_,100){
        double mi = (le + ri) / 2.0;
        VD c(n);
        REP(i,n) c[i] = line[i].second + line[i].first * mi;
        VI p = compress_coordinate(c);
        BIT bit(n);
        ll tmp = 0;
        REP(i,n){
            tmp += bit.sum(p[i]);
            bit.add(p[i],1);
        }
        if (tmp >= k) ri = mi;
        else le = mi;
    }
    return ri;
}

int main() {
    int n;
    cin >> n;
    vector<double> a(n), b(n), c(n);
    REP(i,n) cin >> a[i] >> b[i] >> c[i];

    ll k = ((n * (n-1) / 2) + 1) / 2;

    double ansx = calc(a, b, c, k);

    REP(i,n) a[i] *= -1.0;
    double ansy = calc(b, a, c, k);

    printf("%.14f %.14f\n", ansx, ansy);

    return 0;
}





Measured memory_bytes: 6276
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.bigint;

enum P = 998244353L;

long pow(long x, long n) {
    long y = 1;
    while (n) {
        if (n%2 == 1) y = (y * x) % P;
        x = x^^2 % P;
        n /= 2;
    }
    return y;
}

void main()
{
    auto N = readln.chomp.to!int;
    auto DS = readln.split.to!(int[]);
    if (DS[0] != 0) {
        writeln(0);
        return;
    }

    auto ds = new long[](N);
    foreach (d; DS) ++ds[d];
    if (ds[0] != 1) {
        writeln(0);
        return;
    }
    long r = 1;
    int c;
    foreach (i, d; ds) {
        if (i != 0) {
            r = (r * pow(ds[i-1], d)) % P;
        }
        c += d;
        if (c == N) break;
    }
    writeln(r);
}

Measured memory_bytes: 4428
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
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; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;


using Real = double;
Real scan() {
    Real x; scanf("%lf", &x);
    return (Real)x;
}
class UnionFind {
public:
	vector<ll> Parent;
	UnionFind(ll N) {
		Parent = vector<ll>(N, -1);
	}
	ll root(ll A) {
		if (Parent[A] < 0) {
			return A;
		}
		return Parent[A] = root(Parent[A]);
	}

	ll size(ll A) {
		return -Parent[root(A)];
	}

	bool connect(ll A, ll B) {
		A = root(A);
		B = root(B);
		if (A == B) {
			return false;
		}
		if (size(A) < size(B)) {
			swap(A, B);
		}

		Parent[A] += Parent[B];
		Parent[B] = A;

		return true;
	}

};

class Edge {
public:
	int source, target;
	Real cost;
	Edge(int source = 0, int target = 0, Real cost = 0) :
		source(source), target(target), cost(cost) {}
	bool operator<(const Edge& e)const {
		return cost < e.cost;
	}
};

Real kuraskal(int N, vector<Edge>& edges) {
	Real totalCost = 0;
	sort(edges.begin(), edges.end());
	UnionFind uni(N + 1);
	for (int i = 0; i < edges.size(); i++) {
		Edge e = edges[i];
		if (uni.root(e.source) != uni.root(e.target)) {
			totalCost += e.cost;
			uni.connect(e.source, e.target);
		}
	}
	return totalCost;
}

Real dist(Real x1, Real y1, Real z1, Real x2, Real y2, Real z2) {
	x2 -= x1; y2 -= y1; z2 -= z1;
	return sqrt(x2 * x2 + y2 * y2 + z2 * z2);
}
void solve() {
	int n; scanf("%d", &n); if (n == 0) exit(0);
    vector<Real> x(n), y(n), z(n), r(n);
	for (int i = 0; i < n; i++) x[i] = scan(), y[i] = scan(), z[i] = scan(), r[i] = scan();
	vector<Edge> edges;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			Real d = max(0.0, dist(x[i], y[i], z[i], x[j], y[j], z[j]) - r[i] - r[j]);
			edges.emplace_back(i, j, d);
		}
	}
	printf("%.3f\n", kuraskal(n, edges));
}

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

    int kkt = 89;
    while (kkt) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3276
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>

#define rep(j, n) for (int i = j; i < n; i++)
#define repd(j, n) for (int i = j; i > n; i--)
#define maxx 100010

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;


int main() {
	ll n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	int dp[maxx][3];
	rep(0, n) {
		cin >> a[i] >> b[i] >> c[i];
	}
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	rep(1, n) {
		dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2]) + a[i]);
		dp[i][1] = max(dp[i - 1][1], max(dp[i - 1][0], dp[i - 1][2]) + b[i]);
		dp[i][2] = max(dp[i - 1][2], max(dp[i - 1][0], dp[i - 1][1]) + c[i]);
	}
	ll ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
/**
 * Created at 1:14 on 2019/03/06
 */

import java.util.*;

public class Main {

  static Scanner sc = new Scanner(System.in);

  static int N;

  public static void main(String[] args) {

    int n = sc.nextInt();
    N = n/2;

    ArrayList<Integer> a = new ArrayList(N);
    ArrayList<Integer> b = new ArrayList(N);

    for (int i=0; i<N; i++) {
      a.add(sc.nextInt());
      b.add(sc.nextInt());
    }

    ArrayList<Pair> rankingA = getRanking(a); //[0] 個数 [1] 数値
    ArrayList<Pair> rankingB = getRanking(b);

    if (rankingA.get(0).val != rankingB.get(0).val) {
      System.out.println(2 * N - rankingA.get(0).frequency - rankingB.get(0).frequency);
    } else {
      System.out.println(2 * N - Math.max(
              rankingA.get(0).frequency + rankingB.get(1).frequency,
              rankingA.get(1).frequency + rankingB.get(0).frequency
      ));
    }

  }

  static ArrayList<Pair> getRanking(ArrayList<Integer> list) {
    ArrayList<Pair> ranking = new ArrayList();

    list.sort(null);

    for (int i=0; i<N; i++) {
      int val = list.get(i);
      for (int j=i+1; j<=N; j++) {
        if (j == N || list.get(j) != val) {
          ranking.add(new Pair(j-i, list.get(i)));
          i = j - 1;
          break;
        }
      }
    }

    ranking.sort((x, y) -> y.frequency-x.frequency);

    if (ranking.size() == 1) {
      ranking.add(new Pair(0, -1));
    }

    return ranking;
  }

  static class Pair {
    int frequency, val;
    Pair(int frequency, int val) {
      this.frequency = frequency;
      this.val = val;
    }
  }

}


Measured memory_bytes: 64060
//কী পেয়েছো তুমি, কী চেয়েছিলে তুমি.? হিসেবটা তোমার বড়ই গড়মিল...!!//
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3F3F3F3F
typedef long long ll;
vector<ll>v;
ll solve(ll n)
{
    int cnt=0;
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
        if (prime[p])
            cnt++;
   return cnt;
}
int main ()
{
    ll n;
    while((scanf("%lld",&n))!=EOF){
    cout<<solve(n)<<endl;
    }
}
/*
5 6
1 0
0 5
1 2
1 3
2 3
3 4
*/



Measured memory_bytes: 4204
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a,b,i,ans,s;
    cin>>n>>a>>b;
    s=n/(a+b);
    i=n%(a+b);
    if(i>=a)
        cout<<s*a+a<<endl;
    else
        cout<<s*a+i<<endl;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{

    ll i,j,k,a,b,c,n,t,m,x,y;
    vector<ll> v,s,su;
    map<string,ll> ma,sa;
    map<string,ll> :: iterator it;
    string st,et;
    cin>>a>>b>>c;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    sort(v.begin(),v.end());
    n = v[2]-v[1];
    v[0] = v[0]+n;
    v[1] = v[1]+n;
    if((v[2]-v[0])%2==0){
        n =n+((v[2]-v[0])/2);
    }
    else {
        n = n+((v[2]-v[0])/2);
        n = n+2;
    }
    cout<<n<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
 bool isprime(int p)
 {
     for(int i=2;i*i<=p;i++)
     {
         if(p%i==0) return false;
     }
     return true;
 }
 int main()
 {
     int num;int count =0;
     cin>>num;
     for(int i=0;i<num;i++)
     {
         int p;
         cin>>p;
         if(isprime(p)) count++;
     }
     cout<<count<<endl;
 }

Measured memory_bytes: 3100
#include<stdio.h>
#include<stdlib.h>
int main(void){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if((b-a)==(c-b)){
		printf("YES\n");
	} else{
		printf("NO\n");
	}
	system("pause");
}

Measured memory_bytes: 1008
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, a=0, t=0, w=0, r=0;
    cin>>n;
    while(n--)
    {
        string s;
        cin>>s;
        if(s=="AC")a++;
        if(s=="TLE")t++;
        if(s=="WA")w++;
        if(s=="RE")r++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<w<<endl;
    cout<<"TLE x "<<t<<endl;
    cout<<"RE x "<<r<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 

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

const int MAX = 510000;
// const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();

    ll n, k; cin >> n >> k;
    Rep(i, 1, k){
        ll ans = COM(n-k+1, i)*COM(k-1, i-1)%MOD;
        co(ans);
    }

    return 0;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
ll inf=1e10;

int main(){
  int N,W,w[100],v[100];
  cin>>N>>W;
  for (int i(0);i<N;i++) cin>>w[i]>>v[i];
  vector<vector<ll>> dp(N, vector<ll>(100001, inf));
  dp[0][0]=0;
  dp[0][v[0]]=w[0];
  for (int i(0);i<N-1;i++){
    for (int j(0);j<=100000;j++){
      if (dp[i][j]!=inf){
        dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
        dp[i+1][j+v[i+1]]=min(dp[i+1][j+v[i+1]],dp[i][j]+w[i+1]);
      }
    }
  }
  for (int i(100000);i>=0;i--){
    if (dp[N-1][i]<=W){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 79488
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define vec1(V,T,a) vector<T> V (a)
#define vec2(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define vec3(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  vec1(a,int,3);
  REP(i,3) cin >> a[i];
  sort(a.begin(), a.end());
  cout << a[0] + a[1] << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define sz(v) (int)v.size()
#define pb push_back

using namespace std;
int N;

int gcd(int n){
    int ct = 0;
    rep1(i,n) if(n % i == 0) ct++;
    return ct;
}

int main(){
    cin >> N;
    int ct = 0;
    for(int i = 105;i <= N; i+=2) if(gcd(i) == 8) ct++;
    cout << ct << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long x,k,d;
    cin>>x>>k>>d;
    
    if(x>0)
    {
        long long t=x/d;
        if(t>=k)
        {
            cout<<x-k*d;
        }
        else 
        {
            x=x-t*d;
            k=k-t;
            if(k%2==0)
            {
            cout<<x;
            }
            else
            cout<<d-x;
        }
        
    }
    else
    {
       long long t=(x*-1)/d; 
      // cout<<t<<" ";
       if(t>=k)
        {
            cout<<(x+k*d)*-1;
        }
        else 
        {
            x=x+t*d;
            k=k-t;
            if(k%2==0)
            {
            cout<<x*-1;
            }
            else
            cout<<d+x;
        }
    }
}

Measured memory_bytes: 3624
h,w = sorted(list(map(int,input().split())))
if h % 3 == 0 or w % 3 == 0:
  ret = 0
else:
  c1 = ((w//3+1)*h)-((w-1-w//3)*(h//2))
  c2 = ((w-w//3)*(h-h//2))-(w//3*h)
  c3 = h
  c4 = ((h//3+1)*w)-((h-1-h//3)*(w//2))
  c5 = ((h-h//3)*(w-w//2))-(h//3*w)
  ret = min(c1,c2,c3,c4,c5)
print(ret)


Measured memory_bytes: 3064
// ------------------------------------
// Date:2018/ 2/24
// Problem:AGC 002 RangeProduct a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()

using ll = long long;

#define MOD 1000000007

int main()
{
  int a,b;
  cin >> a >> b;
  if (a>0) {
    cout << "Positive" << endl;
  } else if (b>0) {
    cout << "Zero" << endl;
  } else {
    cout << ((b-a+1)%2==0?"Positive":"Negative") << endl;
  }
  return 0;
}



Measured memory_bytes: 256
unittest
{
	assert( [ "1905" ].parse.expand.solve == "YYMM" );
	assert( [ "0112" ].parse.expand.solve == "AMBIGUOUS" );
	assert( [ "1700" ].parse.expand.solve == "NA" );
	
	assert( [ "0519" ].parse.expand.solve == "MMYY" );		// 追加ケース
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front;
	return tuple( s );
}

auto solve( string s )
{
	auto na = s[ 0 .. 2 ].to!long;
	auto nb = s[ 2 .. 4 ].to!long;
	if( 1 <= na && na <= 12 && 1 <= nb && nb <= 12 ) return "AMBIGUOUS";
	if( 1 <= na && na <= 12 ) return "MMYY";
	if( 1 <= nb && nb <= 12 ) return "YYMM";
	return "NA";
}


Measured memory_bytes: 256
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>
#include <fstream>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll N;
	cin >> N;
	double v[N];
	for (ll i = 0; i < N; ++i) cin >> v[i];
 
	// 解法
    sort(v, v + N);
    double ans = v[0];
    REP(i,N-1){
        ans = (ans+v[i+1])/2;
    }

	//出力
	printf("%.10f\n", ans); // lld としないとオーバーフローする
	// printf("%lld\n", ans); // lld としないとオーバーフローする
	// if (ans) printf("Yes\n");
	// else printf("No\n");
}


Measured memory_bytes: 256
// Sky's the limit :)
#include<bits/stdc++.h>
using namespace std;
#define int long long

int n, a, b, c;

int& get(char s){
    if(s == 'A')
        return a;
    else if(s == 'B')
        return b;
    else
        return c;
}

signed main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    //int t = 1; cin >> t; while(t--)
    {
        cin >> n >> a >> b >> c;
        string s[n];
        vector<int> nxt[3];
        for(int i = 0; i < n; i++) {
            cin >> s[i];
            nxt[s[i][0] - 'A'].push_back(i);
            nxt[s[i][1] - 'A'].push_back(i);
        }

        vector<char> v;
        for(int i = 0 ; i < n ; i++){
            string& t = s[i];
            int& x = get(t[0]);
            int& y = get(t[1]);

            if(!x) {
                x++;
                y--;
                v.push_back(t[0]);
            }
            else if(!y) {
                y++;
                x--;
                v.push_back(t[1]);
            }
            else if(x > 1 || y > 1) {
                if(x < y){
                    x++;
                    y--;
                    v.push_back(t[0]);
                }
                else {
                    x--;
                    y++;
                    v.push_back(t[1]);
                }
            }
            else {
                int p = t[0] - 'A';
                int nx = upper_bound(nxt[p].begin(), nxt[p].end(), i) - nxt[p].begin();
                if(nx == nxt[p].size())
                    nx = 1e9;
                else
                    nx = nxt[p][nx];
                p = t[1] - 'A';
                int ny = upper_bound(nxt[p].begin(), nxt[p].end(), i) - nxt[p].begin();
                if(ny == nxt[p].size())
                    ny = 1e9;
                else
                    ny = nxt[p][ny];
                
                if(nx < ny){
                    x++;
                    y--;
                    v.push_back(t[0]);
                }
                else {
                    x--;
                    y++;
                    v.push_back(t[1]);
                }
            }

            if (a < 0 || b < 0 || c < 0)
                return cout << "No\n", 0;
        }

        cout << "Yes\n";
        for(auto x : v)
            cout << x << '\n';
    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 8732
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    L = list(map(int, input().split()))

    L.sort()
    count = 0
    for j in range(1, N - 1):
        for i in range(j):
            if L[i] == L[j]:
                break
            t = L[i] + L[j]
            for k in range(j + 1, N):
                if L[j] != L[k]:
                    if t > L[k]:
                        count += 1
                    else:
                        break

    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 67956
# ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●     ●●●●●            
# ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●● ●●●●●●●●●●●●●●●          ●   ●      
# ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●● ●●●●●●●●●●●●●●●●     ●●            
# ●●●●●●●●●●●●●●●● ●●●●●●●●●●●●●●●●●●●●●  ● ●●●●●●●●●●●●●●●●●●     ●          
# ●●●●●●●●●●●●●●●●●  ●●●●●●●●●●●●●●●●●● ●    ●●●●●●●   ●●●●●●●●●●      ●      
# ●●●●●●●●●●●●●●●●●●● ●●●●●●●●●●●●●●●●  ●   ●●●●●●●  ●      ●●●●  ●●●●        
# ●●●●●●●●●●●●● ●● ●    ●●●●●●●●●        ● ●        ●● ●●●                    
# ●●●●●●●●●●●●●●    ●     ●●●           ● ●●●    ●  ●●  ●●●●●●●●              
# ●●●●●● ●●●●●●●●                        ●●●●●●●●●  ●   ●●●●●●●●   ●●●        
# ●●  ●●●  ●●●●     ●●●●●                  ●●●●●●●       ●● ●●●●  ●    ●      
# ●●      ●   ●●●●●●●●●●● ●                 ●●●●         ●  ●●●           ●   
# ●●       ●●●●●    ●                                  ●    ●●               ●
# ●●     ●●●●●●●●                                    ●●    ●                  
# ●●     ●●●●●●●●●●●●●●                      ●          ●                     
# ●●●●  ●●●●●●●●●●●●●●●                                      ●                
# ●●●●●       ●●●●●                                          ●                
# ●●●●●●●                                    ●●●                              
# ●●●●●●●●●●                          ●  ●●●●●●●●                             
# ●●●●●●●●● ●  ●                  ●●●●●●●●●●●●●●●         ●                   
# ●●●●●●●●●●●●                  ●●●●●●●●●●●●●●●●●        ●                    
# ●●●●●●●●●●●●●●●                ●●●●●●●●●●●●●●●       ●                      
# ●    ●●●●●●●●●●●                 ●●●●●●●●●●                                 
# ●●●●●●●●●●●●●●●●●                                                           
# ●●●●●●●●●●●●●●●●● ●●                           ●                            

n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
    if v[i] - c[i] > 0:
        ans += v[i] - c[i]

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0,w=0;
std::cin >> x>>y;
repone(i,10001){
  if((int)(i*0.08)==x&&(int)(i*0.1)==y){
    std::cout << i << '\n';
    return 0;
  }
}
std::cout << -1 << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


int main(){
    cin>>N>>M;
    vec food(M,0);
    rep(i,N){
        cin>>K;
        rep(j,K){
            cin>>A;
            ++food.at(A-1);
        }
    }
    ll ans = 0;
    rep(i,M){
        if(food[i] == N) ++ans;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio (false) ;cin.tie(NULL);
#define tc  int t;cin>>t;for(int i=0;i<t;i++)
#define ll long long int
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define um(a,b) unordered_map<a,b>
#define vv(a) vector<a>
#define pp(a,b) pair<a,b>
ll power(ll a,ll b,ll mod){  ll ans=1;  while(b>0){
  if(b&1){ ans=(ans*a)%mod;} a=(a*a)%mod;  b=b/2; } return ans;}

int main(){
FIO
  ll n;
  cin>>n;
  ll arr[n];
  forn(i,n){
   cin>>arr[i];
  }
 sort(arr,arr+n,greater<int>());
 ll ans=arr[0];
 ll count=n-2;
 for(int i=1;i<n;i++){
    if(count){
        count--;
        ans+=arr[i];
    }
    if(count){
        count--;
        ans+=arr[i];
    }
 }
 cout<<ans<<endl;



}


Measured memory_bytes: 5192
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    
    rui = [a[0]]
    for i in range(1, n):
        rui.append(rui[i - 1] + a[i])
    rui = [0] + rui
    ansl = []
    for i in range(n):
        for j in range(i,n):
            ansl.append(rui[j + 1] - rui[i])
    ansl = sorted(ansl, reverse=True)
    
    cnt = 0
    ansbit = 0
    L = []
    for i in range(51):
        bit = (1 << (50 - i))
        l = []
        for j in range(len(ansl)):
            if ansl[j] & bit == 0:
                l.append(ansl[j])
            else:
                L.append(ansl[j])
                cnt += 1
        if cnt >= k:
            ansbit = i
            break
        else:
            L = []
        # ansl = l

    ans = 0
    for i in range(51):
        bit = (1 << (50 - i))
        LL = []
        cnt = 0
        for j in range(len(L)):
            if L[j] & bit != 0:
                cnt+=1
                LL.append(L[j])

        if cnt >= k:
            L = LL
            ans |= bit

        if len(L) < k:
            break
                

    
    print(ans)
    
                    


if __name__ == '__main__':
    main()


Measured memory_bytes: 147632
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4
0 1 2
1 2 1
1 3 3

output:
5
"""

import sys
from math import isinf
from collections import deque


def generate_adj_table(v_table, init_adj_table):
    for each in v_table:
        source, target, cost = map(int, each)
        init_adj_table[source][target] = cost
        init_adj_table[target][source] = cost

    return init_adj_table


def graph_bfs(current, v_num, adj_table):
    queue = deque()
    distance = [float('inf')] * v_num
    distance[current] = 0
    queue.appendleft(current)

    while queue:
        current = queue.popleft()
        for adj, cost in adj_table[current].items():
            if isinf(distance[adj]):
                distance[adj] = distance[current] + cost
                queue.append(adj)
    return distance


def calc_tree_diameter(v_num, adj_table):
    # init x(random node) -> bridge vertex
    init_v = 0
    distance_1 = graph_bfs(init_v, v_num, adj_table)
    diameter, bridge_v = 0, 0
    for v, dis_1 in enumerate(distance_1):
        if isinf(dis_1):
            continue
        elif diameter < dis_1:
            diameter = dis_1
            bridge_v = v

    # bridge vertex -> y
    distance_2 = graph_bfs(bridge_v, v_num, adj_table)
    diameter = 0
    for dis_2 in distance_2:
        if isinf(dis_2):
            continue
        diameter = max(diameter, dis_2)

    return diameter


def solve():
    _input = sys.stdin.readlines()
    v_num = int(_input[0])
    edges = map(lambda x: x.split(), _input[1:])

    init_adj_table = tuple(dict() for _ in range(v_num))
    adj_table = generate_adj_table(edges, init_adj_table)
    ans = calc_tree_diameter(v_num, adj_table)
    print(ans)
    return None


if __name__ == '__main__':
    solve()

Measured memory_bytes: 62864
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
typedef pair<ll, int> PII;
constexpr int MAXN = 100000 + 5;
constexpr ll INF = 100000LL * 1000000000 + 100;
constexpr ll MOD = 1000000000 + 7;
int N, M, S, T;
int U, V;
ll D;
ll dad1[MAXN];
ll dist1[MAXN];

ll dad2[MAXN];
ll dist2[MAXN];
int UU[2 * MAXN];
int VV[2 * MAXN];
ll DD[2 * MAXN];
vector<vector<PII>> edges(MAXN);
ll dd(int S, int T, ll *dad, ll *dist) {
  // use priority queue in which top element has the "smallest" priority
  fill(dist, dist + N + 1, INF);
  dad[S] = 1;
  priority_queue<PII, vector<PII>, greater<PII>> Q;
  Q.push(make_pair(0, S));
  dist[S] = 0;
  bool arr = false;
  while (!Q.empty()) {
    PII p = Q.top();
    Q.pop();
    int here = p.second;
    if (here == T) {
      arr = true;
    }
    if (dist[here] != p.first) continue;
    if (arr && dist[here] > dist[T]) break;
    for (vector<PII>::iterator it = edges[here].begin();
         it != edges[here].end(); it++) {
      if (dist[here] + it->first < dist[it->second]) {
        dist[it->second] = dist[here] + it->first;
        dad[it->second] = dad[here];
        Q.push(make_pair(dist[it->second], it->second));
      } else if (dist[here] + it->first == dist[it->second]) {
        dist[it->second] = dist[here] + it->first;
        dad[it->second] += dad[here];
        dad[it->second] %= MOD;
      }
    }
  }

  return dist[T];
}
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> M >> S >> T;

  for (int i = 0; i < M; ++i) {
    cin >> U >> V >> D;
    UU[i] = U;
    VV[i] = V;
    DD[i] = D;
    edges[U].push_back(make_pair(D, V));
    edges[V].push_back(make_pair(D, U));
  }
  const ll mindist = dd(S, T, dad1, dist1);
  // cerr << "shortest path: " << mindist << endl;
  dd(T, S, dad2, dist2);
  ll tot = (dad1[T] * dad1[T]) % MOD;
  // cerr << "tot: " << tot << endl;
  for (int i = 1; i <= N; ++i) {
    if (dist1[i] == dist2[i] && dist1[i] == mindist / 2) {
      ll dec = (dad1[i] * dad2[i]) % MOD;
      dec = dec * dec % MOD;
      tot -= dec;
      tot %= MOD;
      tot += MOD;
      tot %= MOD;
    }
  }
  // cerr << "tot: " << tot << endl;

  for (int i = 0; i < M; ++i) {
    const ll d = DD[i];
    int u = UU[i];
    int v = VV[i];
    if (dist1[u] + d + dist2[v] == mindist && dist1[u] < mindist / 2 &&
        dist2[v] < mindist / 2) {
      ll dec = (dad1[u] * dad2[v]) % MOD;
      dec = dec * dec % MOD;
      tot -= dec;
      tot %= MOD;
      tot += MOD;
      tot %= MOD;
    } else {
      swap(u, v);
      if (dist1[u] + d + dist2[v] == mindist && dist1[u] < mindist / 2 &&
          dist2[v] < mindist / 2) {
      ll dec = (dad1[u] * dad2[v]) % MOD;
      dec = dec * dec % MOD;
      tot -= dec;
      tot %= MOD;
      tot += MOD;
      tot %= MOD;
      
      }
    }
  }
  cout << tot;
}

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

using namespace std;

using ll = long long;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(3 * n), sc(n + 1);
    for (int i = 0; i < 3 * n; ++i) cin >> a[i];

    priority_queue<ll> pq[2];
    for (ll i = 0, sum[4] = {0, 0, 0, 0}; i < 2 * n; ++i) {
        sum[0] += a[i]; pq[0].push(-a[i]);
        sum[1] += a[3 * n - i - 1]; pq[1].push(a[3 * n - i - 1]);

        if (n <= i) {
            sum[2] -= pq[0].top(); pq[0].pop();
            sum[3] += pq[1].top(); pq[1].pop();
        }
        if (n - 1 <= i) {
            sc[i - n + 1] += sum[0] - sum[2];
            sc[2 * n - i - 1] -= sum[1] - sum[3];
        }
    }

    cout << *max_element(sc.begin(), sc.end()) << endl;

    return 0;
}


Measured memory_bytes: 5108
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author bcools
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] spots = new int[n + 2];
            int total = 0;
            spots[0] = 0;
            spots[n + 1] = 0;
            for (int i = 1; i <= n; ++i) {
                spots[i] = in.nextInt();
                total += Math.abs(spots[i] - spots[i - 1]);
            }
            total += Math.abs(spots[n]);
            for (int i = 1; i <= n; ++i) {
                if ((spots[i - 1] <= spots[i] && spots[i] <= spots[i + 1]) || (spots[i - 1] >= spots[i] && spots[i] >= spots[i + 1]))
                    System.out.println(total);
                else {
                    System.out.println(total - Math.abs(spots[i] - spots[i - 1]) - Math.abs(spots[i] - spots[i + 1]) + Math.abs(spots[i - 1] - spots[i + 1]));
                }
            }
        }

    }
}



Measured memory_bytes: 85152
a, b, c, d = map(int, input().split())
tern = 1
while True:
  if tern % 2 == 1:
    c -= b
    if c <= 0:
      ans = 'Yes'
      break
  else:
    a -= d
    if a <= 0:
      ans = 'No'
      break
  tern += 1
print(ans)

Measured memory_bytes: 9048
#include<iostream>

using namespace std;

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

int n;
long long c[100][100];

int main(){
    cin >> n;

    REP(i, n){
        REP(j, n){
            cin >> c[i][j];
        }
    }

    long long cost = 0;
    REP(i, n){
        for(int j=i+1; j<n; j++){
            cost += min(c[i][j], c[j][i]);
        }
    }

    cout << cost << endl;
}

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

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	int ans = x - a;
	ans %= b;
	cout << ans << endl;
	
	return 0;
}

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

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

    ll X;
    cin >> X;
    ll money = 100;
    ll ans = 0;
    while (money < X) {
        money += money / 100;
        ans++;
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N, D;
    cin >> N >> D;
    vector<vector<int>> grid(N);
    rep(i, N) {
        vector<int> X(D);
        rep(j, D) {
            cin >> X[j];
        }
        grid[i] = X;
    }
    int ans = 0;
    rep(i, N) {
        rep2(j, i+1, N) {
            double tmp = 0;
            rep(k, D) {
                tmp += pow(grid[i][k] - grid[j][k], 2);
            }
            double s = sqrt(tmp);
            int t = (int)s;
            if (s - t == 0) {
                ans++;
            }
        }
    }
    cout << ans << '\n';

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 256
// Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me

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

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
    if (ib == ie) {
        ib = ibuf;
        ie = ibuf + fread(ibuf, 1, BUFF, stdin);
    }
    return ib == ie ? -1 : *ib++;
}

}

LL read() {
    using namespace _buff;
    LL ret = 0;
    bool pos = true;
    char c = getc();
    for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
        assert(~c);
    }
    if (c == '-') {
        pos = false;
        c = getc();
    }
    for (; c >= '0' && c <= '9'; c = getc()) {
        ret = (ret << 3) + (ret << 1) + (c ^ 48);
    }
    return pos ? ret : -ret;
}

const size_t N = 1e5 + 5;

int n, p;
LL m, v, a[N];

bool check(int id) {
    --id;
    LL tot = m * (v - 1);
    int cur = 1;
    for (int i = 0; i < n; ++i) {
        if (i == id) continue;
        if (a[i] > a[id] + m) {
            ++cur;
            tot -= m;
        } else if (tot > 0) {
            tot -= min(m, a[id] + m - a[i]);
        }
    }
    for (int i = 0; i < n && tot > 0; ++i) {
        if (i == id || a[i] > a[id] + m) continue;
        assert(a[i] > a[id]);
        ++cur;
        tot -= a[i] - a[id];
    }
    assert(tot <= 0);
    return cur <= p;
}

int main() {
    n = read();
    m = read();
    v = read();
    p = read();
    generate_n(a, n, read);
    sort(a, a + n, greater<int>());

    int ans = 0, lb = 1, rb = n;
    while (lb <= rb) {
        int mid = (lb + rb) >> 1;
        if (check(mid)) {
            ans = mid;
            lb = mid + 1;
        } else {
            rb = mid - 1;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1536
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    int n;
    int[] a, b, c;

    scan(n);
    a = readln.split.to!(int[]);
    b = readln.split.to!(int[]);
    c = readln.split.to!(int[]);

    a.sort();
    b.sort();
    c.sort();

    a ~= 10^^9 + 7;
    c ~= 10^^9 + 7;

    int l, r;

    long ans;

    foreach (i ; 0 .. n) {
        while (a[l] < b[i]) l++;
        while (c[r] <= b[i]) r++;
        ans += 1L * l * (n - r);
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

int main() {
    long long N, X; cin >> N >> X;
    long long res = N; // 最初の 2 本の合計の長さ
    long long a = max(N - X, X), b = min(N - X, X); // 最初の 2 本の平行四辺形

    // Euclid の互除法を非再帰で回してみる
    while (b) {
        long long q = a / b;
        long long r = a % b;

        res += (b * 2) * q; // 答えを加算
        if (r == 0) res -= b; // 最後だけ「対角線」のみになるので
            
        a = b, b = r; // 次の平行四辺形は (b, r)
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> ans(n, 0);
  for (int i = 1; i <= n-1; ++i) {
    for (int j = i+1; j <= n; ++j) {
      int m = min(j-i, min(abs(x-i)+1+abs(y-j), abs(y-i)+1+abs(x-j)));
      ans[m]++;
    }
  }
  for (int i = 1; i < n; ++i) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int i = 0;
    int N;
    char S[100005][4];
    scanf("%d", &N);
    for (i = 0; i < N;i++){
        scanf("%s", S[i]);
    }

    int ac = 0, wa = 0, tle = 0, re = 0;
    for (i = 0; i < N;i++){
        if(S[i][0]=='A'){
            ac++;
        }else if(S[i][0]=='W'){
            wa++;
        }else if(S[i][0]=='T'){
            tle++;
        }else if(S[i][0]=='R'){
            re++;
        }
    }
    printf("AC x %d\n", ac);
    printf("WA x %d\n", wa);
    printf("TLE x %d\n", tle);
    printf("RE x %d\n", re);
    return 0;
}

Measured memory_bytes: 2092
implicit none
integer :: n
integer, allocatable :: a(:)
integer :: i,j,k,maxk
logical :: flg

read *,n
allocate(a(n))
read *,(a(i),i=1,n)

i = n
flg = .false.
do while (i > 1 .or. flg)
   i = (i * 10) / 13
   if (i < 1) then
      i = 1
   else if (i == 9 .or. i == 10) then 
      i = 11
   endif
   flg = .false.
   do j = 1, n-i
      if (a(j) > a(j+i)) then
         k = a(j) 
         a(j) = a(j+i)
         a(j+i) = k
         flg = .true.
      endif
   enddo
enddo

i = 1
j = 1
maxk = 1
do while (j < n)
   do while (a(j) - a(i) <= 2 .and. j <= n)
      j = j + 1
   enddo
   k = j - i
   if (k > maxk) then
      maxk = k
   endif
   do while (a(j) - a(i) > 2 .and. i < j)
      i = i + 1
   enddo
enddo

print '(i0)',maxk
end

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

using namespace std;

int main() {
    int n, k, c, i, j, dap=0, x, y, sta, inza;
    pair<int, int> front[200007];
    pair<int, int> back[200007];
    char s[200004];
    scanf("%d %d %d", &n, &k, &c);
    scanf("%s", s+1);
    x=1;
    while(s[x]!='\0')
        x++;
    x--;
    front[0].first=0;
    front[0].second=0;
    sta=1000000;
    inza=0;
    for(i=1;i<=x;i++)
    {
        if((s[i]=='o')&&(inza==0))
        {
            sta=i+c;
            inza=1;
        }
        if(i==sta)
        {
            front[i].first=1+front[i-1].first;
            front[i].second=i;
            sta=1000000;
            inza=0;
        }
        else
        {
            front[i].first=front[i-1].first;
            front[i].second=front[i-1].second;
        }
    }
    
    back[x+1].first=0;
    back[x+1].second=100000000;
    sta=1000000;
    inza=0;
    for(i=x;i>=1;i--)
    {
        if(s[i]=='x')
            {
                back[i].first=back[i+1].first;
                back[i].second=back[i+1].second;
            }
        else
        {
            if((i==x)||(back[i+1].first==0))
            {
                back[i].first=1;
                back[i].second=i;
            }
            if((back[i+1].first)==(back[i+c+1].first))
            {
                back[i].first=back[i+c+1].first+1;
                back[i].second=i;
            }
            else
            {
                back[i].first=back[i+1].first;
                back[i].second=back[i+1].second;
            }
        }
    }
    
    for(i=1;i<=x;i++)
    {
        if(s[i]=='o')
        {
            if((front[i-1].first+back[i+1].first)<(k-1))
                printf("%d\n", i);
            else if((front[i-1].first+back[i+1].first)==(k-1))
            {
                y=front[i-1].second+1;
                while(s[y]=='x')
                {
                    y++;
                    if(y>=i)
                        break;
                }
                if(y>=i)
                    printf("%d\n", i);
                else
                {
                    if((y+c)<back[i+1].second)
                        {}
                    else
                        printf("%d\n", i);
                }
            }
        }
    }
    
 return 0;
}

Measured memory_bytes: 4864
import Control.Applicative

sort [] = []
sort (x:xs) = 
    sort lt ++ [x] ++ sort gt
    where lt = [y|y<-xs,y<x]
          gt = [y|y<-xs,y>=x]

sstr [x] = show x
sstr (x:xs) = show x ++ " " ++ sstr xs
main = do
    ss <- words <$> getLine
    let a = take 3 [read x::Int| x<-ss]
    putStrLn $ sstr[x|x<-sort a]

Measured memory_bytes: 3536
from collections import Counter
from sys import exit, stdin
N = int(stdin.readline().rstrip())
A = Counter(int(_) for _ in stdin.readline().rstrip().split())
ans = []
for k, v in A.items():
    if k-v > 0:
        ans.append(v)
    elif k-v < 0:
        ans.append(abs(k-v))
print(sum(ans))

Measured memory_bytes: 23660
#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define eps 1e-9

using namespace std;

int main()
{

    ll t,n,m,f,a,b,c,l,r,q,k,x,y,z,ans,mn,mx,sum=0;
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    cin>>n>>x>>t;

    cout<<((n+x-1)/x)*t<<endl;


}




Measured memory_bytes: 3560
n = int(input())

keta = len(str(n))
ans = 0
#fugo =[0]*pow(2,keta-1)
for i in range(pow(2,keta-1)):
  shiki = str(n)[0]
  temp = [0]*(keta-1)
  for j in range(keta-1):
    if (i>>j)&1 == 1:
      temp[j] = "+"
    else:
      temp[j] = ""
    shiki += temp[j]+str(n)[j+1]
  ans += eval(shiki)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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

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

int main()
{
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}

Measured memory_bytes: 3636