akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<cmath>
#include<sstream>
#include<iomanip>
#include <map>
#include <stack>

struct max_min
{
    int64_t max = 0;
    int64_t min = 0;
};

const int64_t cc = pow( 10, 9 ) + 7;
//std::cout<< std::fixed << std::setprecision(10) << ( double )( max ) / 2;
bool sort_pair( std::pair< std::string, int64_t > origin, std::pair< std::string, int64_t > another )
{
    return origin.second  > another.second;
}


int main()
{
    std::string word = "aa";
    int64_t a,b,c,d,e,f;

    std::vector< std::vector< int64_t > > list;
    std::vector< int64_t > instance;
    bool ll[3][3];
    
    for( int i = 0; i < 3; i++ )
    {
        instance.clear();
        
        for( int r = 0; r < 3; r++ )
        {
            std::cin>> a;
            instance.push_back( a );
            ll[i][r] = false;
        }

        list.push_back( instance );
    }

    std::cin>> a;
    instance.clear();

    for( int i = 0; i < a; i++ )
    {
        std::cin>> b;
        instance.push_back( b );
    }

    for( int i = 0; i < instance.size(); i++ )
    {
        for( int r = 0; r < 3; r++ )
        {
            for( int t = 0; t < 3; t++ )
            {
                if( list[r][t] == instance[i] )
                {
                    ll[r][t] = true;
                }
            }
        }
    }

    bool ok = false;
    
    if( ll[0][0]
        && ll[1][1]
        && ll[2][2] )
    {
        ok = true;
    }
    else if( ll[0][2]
             && ll[1][1]
             && ll[2][0] )
    {
        ok = true;
    }
    else if( ll[0][0]
             && ll[0][1]
             && ll[0][2] )
    {
        ok = true;
    }
    else if( ll[1][0]
             && ll[1][1]
             && ll[1][2] )
    {
        ok = true;
    }
    else if( ll[2][0]
             && ll[2][1]
             && ll[2][2] )
    {
        ok = true;
    }
    else if( ll[0][0]
             && ll[1][0]
             && ll[2][0] )
    {
        ok = true;
    }
    else if( ll[0][1]
             && ll[1][1]
             && ll[2][1] )
    {
        ok = true;
    }
    else if( ll[0][2]
             && ll[1][2]
             && ll[2][2] )
    {
        ok = true;
    }


    if( ok )
    {
        std::cout<< "Yes\n";
    }
    else
    {
        std::cout<< "No\n";
    }
}


Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << 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; }

void solve() {
	int n; cin >> n;
    vector<vector<int>> g(n + 1, vector<int>());
    int m = 0;
    for(int i = 1; i <= n; ++i) {
        for(int j = i + 1; j <= n; ++j) {
            if(n % 2 == 0) {
                if(i + j != n + 1) {
                    g[i].pb(j);
                    ++m;
                }
            } else {
                if(i + j != n) {
                    g[i].pb(j);
                    ++m;
                }
            }
        }
    }
    cout << m << endl;
    for(int i = 1; i <= n; ++i) {
        for(auto v: g[i]) {
            cout << i << " " << v << endl;
        }
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 256
def solve():
    N = int(input())
    A = [0] + [int(i) for i in input().split()] + [0]
    A_edge = []
    # 頂点と底辺のみにデータを絞る
    up_flg = True
    for i in range(1, len(A) - 1):
        if up_flg:
            if A[i] > A[i + 1]:
                A_edge.append([A[i], up_flg])
                up_flg = not up_flg
        else:
            if A[i] < A[i + 1]:
                A_edge.append([A[i], up_flg])
                up_flg = not up_flg
    A_edge.sort()  # 沈んでいく順に並べ替え
    # 島を数える
    island_count = 1
    max_island_count = 1
    for i in range(len(A_edge) - 1):
        if A_edge[i][1]:
            island_count -= 1
        else:
            island_count += 1
        if A_edge[i][0] < A_edge[i + 1][0]:
            max_island_count = max(max_island_count, island_count)
    # 島の高さがすべて0の時の考慮
    if max(A) <= 0:
        max_island_count = 0
    print(max_island_count)


if __name__ == '__main__':
    solve()



Measured memory_bytes: 16768
#include <stdio.h>
 
int main(){
    int n,x,count;
    while(true){
        scanf("%d %d",&n,&x);
        if(n == 0 && x == 0) break;
        count = 0;
        for(int min = 1; min < x/3 && min <= n-2;min++){
            for(int middle = min+1;middle < x - (min+middle) && middle <= n-1; middle++){
                if(x-(min+middle) <= n) count++;
            }
        }
        printf("%d\n",count);
    }
 
}
 


Measured memory_bytes: 2644
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int max = 0;
    long ans = 0;

    for (int i = 0; i < n; i++) {
      int tmp = sc.nextInt();
      max = Math.max(max, tmp);
      ans += max - tmp;
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 58444
s = list(input())
n = int(input())
rev = False
pre = []
suf = []
for _ in range(n):
    q = input()
    if q == '1':
        rev = not rev
    else:
        t,f,c = q.split()
        if f == '1':
            if rev:
                suf += [c]
            else:
                pre += [c]
        else:
            if rev:
                pre += [c]
            else:
                suf += [c]

if rev:
    print(''.join(reversed(suf)) + ''.join(reversed(s)) + ''.join(pre))
else:
    print(''.join(reversed(pre)) + ''.join(s) + ''.join(suf))

Measured memory_bytes: 6944
// 2020-08-15 21:46:12
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

const ll inf = 1e18;
ll score[5050][5050];
void answer() {
  ll n, k;
  ll ans = -inf;
  cin >> n >> k;
  vector<ll> p(n);
  rep(i, n) {
    cin >> p[i];
    p[i]--;
  }
  vector<ll> c(n);
  rep(i, n) cin >> c[i];
  rep(s, n) {
    ll now = 0, ki = 0, cur = s, freq = 0;
    while(ki < k) {
      cur = p[cur];
      ki++;
      now += c[cur];
      score[s][ki] = now;
      chmax(ans, now);
      if(cur == s) {
        freq = ki;
        break;
      }
    }
    if(freq > 0 && freq < k && score[s][freq] > 0) {
      ll x = k / freq, r = k % freq;
      repc(rr, r) chmax(ans, score[s][freq] * x + score[s][rr]);
      if(r == 0) {
        repc(rr, freq) chmax(ans, score[s][freq] * (x-1) + score[s][rr]);
      }
    }
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 200944
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
using namespace std;

bool comp(const string &s, const string &t){
	if( s.size() < t.size() ) return true;
	if( s.size() > t.size() ) return false;
	return s < t;
}

int main(){
	int n;
	map<string, int> m;
	vector<string> v;
	
	cin >> n;
	for(int i=0 ; i < n ; i++ ){
		string s;
		int k;
		cin >> s >> k;
		
		if( m.count(s) ){
			m[s] += k;
		}else{
			m[s] = k;
			v.push_back(s);
		}
	}
	sort(v.begin(), v.end(), comp);
	for(int i=0 ; i < v.size() ; i++ ){
		cout << v[i] << " " << m[v[i]] << endl;
	}
}

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

int main()
{
	int a,b,x;
	cin>>a>>b;
	
	x=(a+b)/2;
	
	if((a+b)%2==1)
	   cout<<x+1<<endl;
	else
	   cout<<x<<endl;
	   
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
  
  char str[6];
  cin>>str;
  int second = (str[3]-'0')+(str[2]-'0')*10;
  int first = (str[1]-'0')+(str[0]-'0')*10;
  

  int yymm=0,mmyy=0;
  if(first>0&&first<=12)
    mmyy=1;
  if(second>0&&second<=12)
    yymm=1;
  if(yymm==1&&mmyy==1)
    cout<<"AMBIGUOUS";
  else if(yymm==1)
    cout<<"YYMM";
   else if(mmyy==1)
    cout<<"MMYY";
  else
    cout<<"NA";
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
using System.Text;
using static System.Console;
using static System.Math;
class Simple {
    private int N;
    private int[] A;
    void Solve() {
        //input
        N = io.Int;
        A = new int[N];
        for(int i = 0; i < N; ++i) {
            A[i] = io.Int;            
        }        
        //cal
        Array.Sort(A);        
        var aMax = A[N - 1];
        var mid = (aMax + 1) / 2;
        var mDiff = int.MaxValue;
        var ans = int.MinValue;
        foreach(var v in A) {
            var tmp = Abs(v - mid);
            if(tmp < mDiff) {
                mDiff = tmp;
                ans = v;
            }
        }
        //out
        WriteLine($"{aMax} {ans}");
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream();
    private void Stream() {
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //SetIn(exStdIn);
        Solve();
        io.Flush();
    }
}
class SimpleIO {
    string[] _nextBuffer;
    int _bufferCnt;
    char[] cs = new char[] {' ', '"', ','};
    StreamWriter sw = new StreamWriter(OpenStandardOutput()) {
#if DEBUG
        AutoFlush = true
#else
        AutoFlush = false
#endif
    };
    public SimpleIO() {
        _nextBuffer = new string[0];
        _bufferCnt = 0;
        SetOut(sw);
    }
    string Next() {
        if(_bufferCnt < _nextBuffer.Length)
            return _nextBuffer[_bufferCnt++];
        var st = ReadLine();
        while(st == "")
            st = ReadLine();
        _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        _bufferCnt = 0;
        return _nextBuffer[_bufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void Flush() => Out.Flush();
}


Measured memory_bytes: 21088
#include <stdio.h>

int main(void)
{
	int i;
	int n;
	int a,b, ptA, ptB;

	while(1)
	{
		scanf("%d", &n);
		if(n == 0)break;

		ptA=0; ptB=0;
		for(i=0; i<n; i++)
		{
			scanf("%d %d", &a, &b);
			     if(a>b)ptA += a+b;
			else if(b>a)ptB += a+b;
			else{ ptA+=a; ptB+=b; }
		}
		printf("%d %d\n", ptA, ptB);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define ll long long
#define p pair<ll, ll>
#define INF (1LL<<62)
using namespace std;

int main(){

  int n, k;
  ll ans = INF;

  cin >> n >> k;
  vector<ll> x, y;
  vector<p> v;

  for(int i = 0; i < n; i++){
    int a, b;
    cin >> a >> b;
    x.push_back(a), y.push_back(b);
    v.push_back(p(a, b));
  }

  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  for(int dx = 0; dx < n; dx++){
    for(int ux = dx+1; ux < n; ux++){
      for(int dy = 0; dy < n; dy++){
        for(int uy = dy+1; uy < n; uy++){
          int cnt = 0;
          ll x1 = x[dx], x2 = x[ux];
          ll y1 = y[dy], y2 = y[uy];
          for(int i = 0; i < n; i++){
            if(x1 <= v[i].first and v[i].first <= x2 and y1 <= v[i].second and v[i].second <= y2){
              cnt++;
            }
          }
          if(cnt >= k) ans = min(ans, (x2 - x1) * (y2 - y1));
        }
      }
    }
  }

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define all(a) a.begin(),a.end()
typedef pair<int,int> P;
const long long mod=998244353;
const long long inf=1ll<<61;
int rr[200006],rw[200006];
signed main(){
	int n;cin>>n;
	string s;cin>>s;
	int r=0;
	rep(i,n)if(s[i]=='R')r++;
	int ans=inf;
	rep(i,n){
		if(s[i]=='R')rr[i+1]++;
		else rw[i+1]++;
	}
	rep(i,n){
		rr[i+1]+=rr[i];
		rw[i+1]+=rw[i];
	}
	for(int i=0;i<=n;i++){//rをi個
		int res=(rw[i]+rr[n]-rr[i]+abs(r-i))/2;
		ans=min(ans,res);
	}
	cout<<ans<<endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define forin(i,array) for(auto& x:array)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mod 1000000007
#define inf 10000000000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;

vll s(100009),t(100009);
vll truth(100009);

int vec[]={2,5,5,4,5,6,3,7,6};
vint arr;
vint ans(100000);

vector<string> dp(100000);

string strmax(string a,string b){
    if(a=="err")return b;
    if(a.length()<b.length())return b;
    if(a.length()>b.length())return a;
    if(a<=b)return b;
    else return a;
}

string strfunc(int a,string b){
    stringstream ss;
    ss<<a<<b;
    return ss.str();
}

int main(){
    int n,m;
    cin>>n>>m;
    rep(i,m){
        int x;
        cin>>x;
        arr.pb(x-1);
    }
    rep(i,n+1){
        if(i==0)dp[i]="";
        else dp[i]="err";
    }
    reps(i,1,n+1){
        rep(j,9){
            if(find(all(arr),j)==arr.end())continue;
            if(i-vec[j]<0)continue;
            if(dp[i-vec[j]]=="err")continue;
            dp[i]=strmax(dp[i],strfunc(j+1,dp[i-vec[j]]));
        }
    }

    cout<<dp[n]<<endl;
}

Measured memory_bytes: 35840
#include <iostream>
#include <vector>
#include <string>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;

void In(ll& I)
{
	cin >> I;
}

void In(vl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void Out(ll& O)
{
	cout << O;
}

void Out(vl& O)
{
	for (auto& o : O)
	{
		cout << o;
	}
}

int main()
{
	string S;

	cin >> S;

	ll N = S.size();

	vl A(N);

	for (int i = 0; i < N; i++)A[i] = S[i] - '0';

	ll Num10 = 0;
	ll Num01 = 0;

	for (int i = 0; i < N; i++)
	{
		if (i % 2 == 1)
		{
			Num10 += (A[i] == 1 ? 1 : 0);
			Num01 += (A[i] == 0 ? 1 : 0);
		}
		else
		{
			Num10 += (A[i] == 0 ? 1 : 0);
			Num01 += (A[i] == 1 ? 1 : 0);
		}
	}

	ll Num = Num10 < Num01 ? Num10 : Num01;

	cout << Num;
	return 0;
}

Measured memory_bytes: 1280
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

constexpr i64 N_A = std::numeric_limits<i64>::max();

class state {
public:
  i64 l2, l1, c, r1, r2;
};

int main() {
  i64 N;
  std::cin >> N;
  std::vector<std::pair<i64, i64>> P;
  for (i64 i = 0; i < N; ++i) {
    i64 P_i;
    std::cin >> P_i;
    P.push_back(std::make_pair(P_i, i));
  }
  std::sort(P.begin(), P.end(), std::greater<std::pair<i64, i64>>());
  std::set<i64> set;
  std::vector<state> status(N);
  for (const std::pair<i64, i64>& pair : P) {
    const auto it = set.insert(pair.second).first;
    const i64 c = pair.second;

    auto l_it = it;
    i64 l1, l2;
    if (l_it == set.begin()) {
      l1 = N_A;
      l2 = -1;
    } else {
      --l_it;
      if (l_it == set.begin()) {
        l1 = *l_it;
        l2 = -1;
      } else {
        l1 = *l_it;
        --l_it;
        l2 = *l_it;
      }
    }

    auto r_it = it;
    i64 r1, r2;
    ++r_it;
    if (r_it == set.end()) {
      r1 = N_A;
      r2 = N;
    } else {
      r1 = *r_it;
      ++r_it;
      if (r_it == set.end()) {
        r2 = N;
      } else {
        r2 = *r_it;
      }
    }

    status[pair.first - 1].l2 = l2;
    status[pair.first - 1].l1 = l1;
    status[pair.first - 1].c = c;
    status[pair.first - 1].r1 = r1;
    status[pair.first - 1].r2 = r2;
  }

  i64 answer = 0;
  for (i64 i = 0; i < N; ++i) {
    if (status[i].l1 != N_A) {
      answer += (i + 1) * (status[i].l1 - status[i].l2) * ((status[i].r1 == N_A ? status[i].r2 : status[i].r1) - status[i].c);
    }
    if (status[i].r1 != N_A) {
      answer += (i + 1) * (status[i].r2 - status[i].r1) * (status[i].c - (status[i].l1 == N_A ? status[i].l2 : status[i].l1));
    }
  }
  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 10352
#include<iostream>
#include<string>
#include<utility>
#include<vector>
#include<algorithm>
using namespace std;

struct Rational{
	int x,y;
	Rational(){}
	Rational(int x,int y){
		this->x=x;
		this->y=y;
	}
	bool operator < (Rational a)const{return x*a.y > a.x*y;}
};

int main(){
	int n;
	while(cin>>n,n){
		vector<pair<Rational,string> > v;
		while(n--){
			string l;
			int p,a,b,c,d,e,f,s,m;
			cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			int income = f*s*m-p;
			v.push_back(make_pair(Rational(income,(a+b+c+(d+e)*m)),l));
		}
		sort(v.begin(),v.end());
		for(int i=0;i<v.size();i++)
			cout<<v[i].second<<endl;
		cout<<'#'<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
int ans=0;
long double dp[303][303][303]={0};

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   //   freopen("q.gir","r",stdin);
   //   freopen("q.cik","w",stdout);
      int n,sum=0;
      cin>>n;
      vector<int>arr;
      int a[4]={0};
      for(int i=0;i<n;i++){
            int x;
            cin>>x;
            arr.pb(x);
            a[x]++;
      }
      for(int i=0;i<303;i++)for(int j=0;j<303;j++)for(int k=0;k<303;k++)dp[i][j][k]=0;
      dp[0][0][0]=1;
      for(int k=0;k<=n;k++){
            for(int j=0;j<=n;j++){
                  for(int i=0;i<=n;i++){
                        if(i+j+k>n||i+j+k==0)continue;
                        if(i!=a[1]||j!=a[2]||k!=a[3])
                        dp[i][j][k]=1.0*n/(i+j+k);
                        if(i>0)dp[i][j][k]+=dp[i-1][j][k]*1.0*i/(i+j+k);
                        if(j>0)dp[i][j][k]+=dp[i+1][j-1][k]*1.0*j/(i+j+k);
                        if(k>0)dp[i][j][k]+=dp[i][j+1][k-1]*1.0*k/(i+j+k);
                  }
            }
      }
      cout<<setprecision(20)<<dp[a[1]][a[2]][a[3]];
}


Measured memory_bytes: 434944
import java.util.ArrayDeque;
import java.util.Arrays;

public class Main {

	private static void solve() {
		int k = ni();
		int[] d = new int[k];
		Arrays.fill(d, Integer.MAX_VALUE / 2);

		ArrayDeque<Integer> queue = new ArrayDeque<>();
		
		queue.add(1);
		d[1] = 1;
		while (queue.size() > 0) {
			int x = queue.pollLast();
			if (x == 0) break;

			int next;
			
			next = (x * 10) % k;
			if (d[next] > d[x]) {
				d[next] = d[x];
				queue.addLast(next);
			}
			
			next = (x + 1) % k;
			if (d[next] > d[x] + 1) {
				d[next] = d[x] + 1;
				queue.addFirst(next);
			}
		}
		
		System.out.println(d[0]);
	}
	
	

	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			@Override
			public void run() {
				long start = System.currentTimeMillis();
				String debug = args.length > 0 ? args[0] : null;
				if (debug != null) {
					try {
						is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
					} catch (Exception e) {
						throw new RuntimeException(e);
					}
				}
				reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
				solve();
				out.flush();
				tr((System.currentTimeMillis() - start) + "ms");
			}
		}, "", 64000000).start();
	}

	private static java.io.InputStream is = System.in;
	private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
	private static java.util.StringTokenizer tokenizer = null;
	private static java.io.BufferedReader reader;

	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new java.util.StringTokenizer(reader.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	private static double nd() {
		return Double.parseDouble(next());
	}

	private static long nl() {
		return Long.parseLong(next());
	}

	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private static char[] ns() {
		return next().toCharArray();
	}

	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}

	private static int[][] ntable(int n, int m) {
		int[][] table = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				table[i][j] = ni();
			}
		}
		return table;
	}

	private static int[][] nlist(int n, int m) {
		int[][] table = new int[m][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				table[j][i] = ni();
			}
		}
		return table;
	}

	private static int ni() {
		return Integer.parseInt(next());
	}

	private static void tr(Object... o) {
		if (is != System.in)
			System.out.println(java.util.Arrays.deepToString(o));
	}
}


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

int main(){
    ll n, a;
    cin >> n >> a;
    if(n % 500 <= a) cout << "Yes" << endl;
    else cout << "No" << 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++)
int main() {
	int a, b;
	cin >> a >> b;
	if (10 > a > 0 && 10 > b > 0) {
		if (82 > (a * b) > 0) {
			cout << a * b << endl;
		}
		else {cout << "-1" << endl;}
	}
	else {cout << "-1" << endl;}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)

vector<pair<int,ll>> adj[100010];
int ans[100010];
void dfs(int x, ll dst=0)  {
	if(dst&1) ans[x]=1;
	else ans[x]=2;
	for(auto i:adj[x]) {
		if(!ans[i.xx]) {
			dfs(i.xx, i.yy+dst);
		}
	}
}

int main() {
	IO;
	int n;
	cin>>n;
	for(int i=1;i<n;++i) {
		int a,b,c;
		cin>>a>>b>>c;
		adj[a].emplace_back(b,c);
		adj[b].emplace_back(a,c);
	}
	dfs(1,0);
	for(int i=1;i<=n;++i) {
		cout<<ans[i]-1<<"\n";
	}
	return 0;
}


Measured memory_bytes: 13020
#include<stdio.h>
int main()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a==b && b==c && c==a)
    printf("No");
 else if(a==b || a==c || b==c)
printf("Yes");
else
printf("No");


return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int a,b;
string s;
inline int read()
{
    register int number_read=0,if_ok_read=1;
    char ch_read=getchar();
    while(ch_read<'0'||ch_read>'9')
    {
        if(ch_read=='-')
            if_ok_read=-1;
        ch_read=getchar();
    }
    while(ch_read>='0'&&ch_read<='9')
    {
        number_read=number_read*10+ch_read-'0';
        ch_read=getchar();
    }
    return number_read*if_ok_read;
}
inline void write(register int x_write)
{
    if(x_write<0)
    {
        putchar('-');
        x_write=-x_write;
    }
    if(x_write>9)
        write(x_write/10);
    putchar(x_write%10+'0');
    return ;
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	a=read(),b=read();
    cin>>s;
    for(int i=0;i<a+b;i++)
    {
        if(s[a]!='-')
        {
            cout<<"No"<<endl;
            return 0;
        }
        if(i!=a)
        {
            if(!(s[i]>='0'&&s[i]<='9'))
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"; 
    putchar('\n');
    return 0;
}


Measured memory_bytes: 256
N,W = map(int,input().split())
w = []
v = []
for i in range(N):
    x,y = map(int,input().split())
    w.append(x)
    v.append(y)

dp = [[0]*(W+1) for j in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if j < w[i]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i])

print(dp[N][W])

Measured memory_bytes: 120300
#include <stdio.h>
int main(void){
    int n, m, c, a[100][20], b[20], i, j, sum=0, cnt=0;
    scanf("%d %d %d", &n, &m, &c);
    for(i=0; i<m; i++)
        scanf("%d", &b[i]);
    for(i=0; i<n; i++, sum=0){
        for(j=0; j<m; j++){
            scanf("%d", &a[i][j]);
            sum += a[i][j] * b[j];
        }
        if(sum+c>0)
            cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 128
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
int main(){
    double in;
    cin >> in;

    cout << in * 2.0 * M_PI;
    return 0;
}

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

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,m,k;
    ll a=1000000007;
    ll ans=0;
    ll kai=0;
	cin >> n >>m >>k;
    fr(i,n){
      kai+=i*(n-i)*m*m;
      kai%=a;
    }
    kai*=COM(n*m-2,k-2)%a;
    ans+=kai;
    kai=0;
    fr(i,m){
      kai+=i*(m-i)*n*n;
      kai%=a;
    }
    kai*=COM(n*m-2,k-2)%a;
    ans+=kai;
    ans%=a;
    cout << ans<<endl; 
}


Measured memory_bytes: 12288
#include <iostream>
#include <map>

int reduce_3to1(int x)
{
  if(x <= 2) {
    return x;
  } else {
    return x%2 == 0 ? 2 : 1;
  }
}

int main()
{
  int N;
  std::cin >> N;
  std::map<int, int> cards;
  for(int i=0; i<N; i++) {
    int a;
    std::cin >> a;
    cards[a]++;
  }

  // we can reduce same 3 cards to 1
  int num_doubles = 0;
  for(auto &c: cards) {
    c.second = reduce_3to1(c.second);
    if(c.second == 2) {
      num_doubles++;
    }
  }

  // couple of double cards can be deleted
  num_doubles %= 2;

  std::cout << cards.size() - num_doubles << std::endl;

  return 0;
}


Measured memory_bytes: 8232
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int mod=1e9+7;
const int INF =LONG_LONG_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int m,n;
    cin>>m>>n;
    char a[m][n];
    for(int i=0;i<m;i++)
        for(int j=0;j<n;j++)
        cin>>a[i][j];
    int dp[m][n];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++)
    {
        if(a[0][i]=='#')break;
        dp[0][i]=1;
    }
    for(int i=0;i<n;i++)
    {
        if(a[i][0]=='#')break;
        dp[i][0]=1;
    }
    for(int i=1;i<m;i++)
    {
        for(int j=1;j<n;j++)
        {
            //cout<<a[i][j]<<" ";
            if(a[i][j]=='#'){dp[i][j]=0;continue;}
            if(i==0||j==0){dp[i][j]=1;continue;}
            dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
        }
        //cout<<endl;
    }
    cout<<dp[m-1][n-1]%mod<<endl;
    return 0;
}


Measured memory_bytes: 9088
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n, x;
int p[2 * maxn];

int read() {
  if (scanf("%d%d", &n, &x) < 2) {
    return false;
  }
  x--;
  return true;
}

void solve() {
  if (x == 0 || x == 2 * n - 2) {
    printf("No\n");
    return;
  }
  printf("Yes\n");
  for (int i = 0; i < 2 * n - 1; i++) {
    p[i] = i;
  }
  rotate(p, p + (x - n + 1 + 2 * n - 1) % (2 * n - 1), p + 2 * n - 1);
  for (int i = 0; i < 2 * n - 1; i++) {
    printf("%d\n", p[i] + 1);
  }
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  ll Ma=n,Mi=1;
  rep(i,m) {
    ll l,r;
    cin >> l >> r;
    Mi=max(Mi,l);
    Ma=min(Ma,r);
  }
  pr(max(0LL,Ma-Mi+1));
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include <stdio.h>
int main(int argc, char const *argv[]) {
  int current[4][3][10] = {0};
  int i, j, k, n;
  int b, f, r, v;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%d %d %d %d", &b, &f, &r, &v);
    current[b - 1][f - 1][r - 1] += v;
  }

  for (i = 0; i < 3; i++) {
    for (j = 0; j < 10; j++) {
      printf(" %d", current[0][i][j]);
    }
    puts("");
  }

  for (i = 1; i < 4; i++) {
    for (j = 0; j < 20; j++) {
      printf("#");
    }
    puts("");
    for (j = 0; j < 3; j++) {
      for (k = 0; k < 10; k++) {
        printf(" %d", current[i][j][k]);
      }
      puts("");
    }
  }

  return 0;
}

Measured memory_bytes: 1040
#include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s)                                                               \
    do {                                                                       \
    } while (0)
#define dump(x)                                                                \
    do {                                                                       \
    } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

void solve() {
    int h, w;
    cin >> h >> w;
    VVI c(10, VI(10)), a(h, VI(w));
    REP(i, 0, 10) REP(j, 0, 10) cin >> c[i][j];
    REP(i, 0, h) REP(j, 0, w) cin >> a[i][j];
    REP(k, 0, 10)
    REP(i, 0, 10) REP(j, 0, 10) c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    int sum = 0;
    REP(i, 0, h) REP(j, 0, w) {
        if (a[i][j] == -1)
            continue;
        sum += c[a[i][j]][1];
    }
    cout << sum << endl;
}

signed main() {
    solve();

    return 0;
}

Measured memory_bytes: 384
def solve():
    Ss = input().rstrip()
    Ts = input().rstrip()

    lenS, lenT = len(Ss), len(Ts)

    ans = lenS
    for i in range(lenS-lenT+1):
#        print('# Ss:', Ss[i:i+lenT], '/ Ts:', Ts)
        num = sum([S != T for S, T in zip(Ss[i:i+lenT], Ts)])
        if num < ans:
            ans = num

    print(ans)


solve()


Measured memory_bytes: 67760
package main

import (
	"container/heap"
	"fmt"
)

func main() {
	var n, m, c int
	fmt.Scan(&n, &m)
	As := make(myIntArray, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&c)
		As[i] = &Item{
			priority: c,
		}
	}
	// this func change interface to heap status, almost like sorting.
	heap.Init(&As)
	var a *Item
	for i := 0; i < m; i++ {
		a = heap.Pop(&As).(*Item)
		a = &Item{
			priority: a.priority / 2,
		}
		heap.Push(&As, a)
	}
	total := 0
	for i := 0; i < n; i++ {
		total += As[i].priority
	}
	fmt.Println(total)
}

type Item struct {
	priority int
}
type myIntArray []*Item

func (h myIntArray) Len() int { return len(h) }

//この＞こっちにしてるのに
func (h myIntArray) Less(i, j int) bool  { return h[i].priority > h[j].priority }
func (h myIntArray) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *myIntArray) Push(x interface{}) { *h = append(*h, x.(*Item)) }

//Popしたら戦闘の大きい値をとってくるのはなんで？
//ｘは↓みたらわかるけど一番お尻の小さい値取ってきているのでは？？？？？？？
func (h *myIntArray) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

Measured memory_bytes: 6016
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
/*int p = 998244353;*/
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
#define end_pr(s) cout << s <<endl;return 0
signed main(){
	int m, f,b; cin >> m >> f>>b;
	if (m + f < b) { cout << "NA" << endl; }
	else {
		int ze = 0;
		cout << max(ze, b - m) << endl;
	}
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 143, task do, 2020/09/011
//ms,
/*
*/

int main(void){
  int N;
  vector<int> l;
  vector<int> record(1001, 0);
  int64_t ans=0;

  cin >>N;
  for(int i=0;i<N;i++){
    int tmp;
    cin >>tmp;
    l.push_back(tmp);
  }

  sort(l.begin(), l.end());
  for(int i=0;i<N;i++){
    for(int j=l[i];j<=1000;j++) record[j]++;
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(i==j) continue;

      int a, b, c_psblty;
      a=l[i]; b=l[j];
      int right=min(a+b-1, 1000);
      int left=abs(b-a);
      c_psblty = record[right]-record[left];

      if(left<a && a<=right){ c_psblty--; /*cout <<"a"<<endl;*/}
      if(left<b && b<=right){ c_psblty--; /*cout <<"b"<<endl;*/}
      ans+=c_psblty;

      //cout <<i <<" "<<j<<" " <<a <<" "<<b <<" " <<left <<" " <<right<<" " <<record[left]<<" " <<record[right] <<endl;
    }
  }
  cout <<ans/6<<endl;

  return 0;
}
/*
制約が小さめだね、n^2は余裕。
a, bを決めたらcの条件は単純に決まるのでそれで全探索する。累積和も使う。
問題は21行目にあって、累積和でも解けて、正三角形周辺が問題。
さて。かぶってても使える場合、使えない場合を見分けないといけない。
カウンタを用意しようにもかぶり方が複雑すぎる。お手上げ。
*/


Measured memory_bytes: 3596
import java.math.*;
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int Y = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int[] p = new int[A];
    int[] q = new int[B];
    int[] r = new int[C];
    for (int i = 0; i < A; i++) p[i] = sc.nextInt();
    for (int i = 0; i < B; i++) q[i] = sc.nextInt();
    for (int i = 0; i < C; i++) r[i] = sc.nextInt();
    sc.close();
    
    long ans = IntStream.concat(IntStream.concat(
        Arrays.stream(p).parallel().sorted().skip(A - X),
        Arrays.stream(q).parallel().sorted().skip(B - Y)),
        Arrays.stream(r))
      .parallel().sorted().skip(C)
      .asLongStream()
      .parallel().sum();

    System.out.println(ans);
  }
}

Measured memory_bytes: 95292
def check s
  abc={a:true, b:true, c:true}
  return "No" if !s || s.empty?
  s.split("").each do |c|
    return "No" unless abc[c.to_sym]
    abc[c.to_sym]=false
  end
  return "Yes"
end

s=gets.chomp
puts check(s)


Measured memory_bytes: 1788
#include<stdio.h>
#include<math.h>

#define N 1000000
#define M 100

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

int main(void){
  int num,cnt,A[N],m,G[M];
  int i;

  G[0] = 1;

  for(i = 1; i < M; i++){
    G[i] = 3*G[i-1] + 1;
  }

  scanf(" %d",&num);

  for(i = 0; i < M; i++){
    if(num < G[i])break;
  }

  m = i;
  
  for(i = 0; i < num; i++){
    scanf(" %d",&A[i]);
  }

  cnt = shellSort(A,G,m,num);

  printf("%d\n",m);
  for(i = m-1; i > 0; i--){
    printf("%d ",G[i]);
  }
  printf("%d\n",G[0]);
  printf("%d\n",cnt);

  for(i = 0; i < num; i++){
    printf("%d\n",A[i]);
  }
  
  
  return 0;
}

int insertionSort(int *A, int num, int g){
  int i,j;
  int v,cnt=0;

  for(i = g; i < num; 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 cnt;
}

int shellSort(int *A, int *G, int m, int num){
  int cnt=0;
  int i;

  for(i = m-1; i >= 0; i--){
    cnt += insertionSort(A,num,G[i]);
  }

  return cnt;
}



Measured memory_bytes: 5672
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		int p[]=new int[n];
		for(int i=0;i<n;i++){
			p[i]=scanner.nextInt();
		}
		Arrays.sort(p);
		int sum=0;
		for(int i=0;i<n;i++){
			
			if(i==n-1){
				sum+=p[i]/2;
			}else{
				sum+=p[i];
			}
		}
		System.out.println(sum);
	}
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


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




int main() 
{ 
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
	
	// int n,t,k; cin >> n >> t >> k;
	// int cnt = t; int time = k;
	// // if (cnt > n) cout << k;
	
	
	// 	if (t == 1){
	// 	 cout << n*k;
	// 	 return 1;
	// 	}
	// 	while (cnt <= n)
	// 	{
	// 		cnt += t;
	// 		time += k;
	// 	}
	// 	cout << time;
	
	string s; cin >> s;
	long long sum = 0;
	for (long long int i = 0; i < s.length(); i++)
	{
		sum += s[i]-'0';
	}
	if (sum % 9 == 0) cout << "Yes";
	else cout << "No";

} 


Measured memory_bytes: 3676
module Main where

import Data.Functor

main :: IO ()
main = do
  { [a,b,c] <- getInts
  ; print (sum [ 1 | x <- [a .. b], mod c x == 0])
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

done :: IO ()
done = return ()

Measured memory_bytes: 4152
#include<iostream>
#include<vector>

using namespace std;
int main(){
	bool exist = false;
	int a, b, c, d, e;
	vector<int> antennas;
	int tmp, k;

	// a-e
	for (size_t i = 0; i < 5; ++i) {
		cin >> tmp;
		antennas.push_back(tmp);
	}
	// k
	cin >> k;

	int num_anntenas = antennas.size();
	for (size_t i = 0; i < num_anntenas; ++i) {
		for (size_t j = i + 1; j < num_anntenas; ++j) {
			if (antennas.at(j) - antennas.at(i) > k) {
				exist = true;
			}
		}
	}

	if (exist) {
		cout << ":(" << endl;
	} else {
		cout << "Yay!" << endl;
	}

	return 0;
}

Measured memory_bytes: 256