akhauriyash/Code-Regression huggingface dataset:
n, m, d = map(int, input().split())
count = 0
a = []
for _ in range(n):
    a.append(input() + "#")
a.append("#" * m)
for i in range(n):
    for j in range(m):
        if a[i][j] == ".":
            for k in range(1, d):
                if a[i + k][j] == "#":
                    break
            else:
                count += 1
            for k in range(1,d):
                if a[i][j + k] == "#":
                    break
            else:
                count += 1
print(count)


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int a;
  cin >> a;
  cout << (a ^ 1);
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3652
import bisect

N,M=map(int,input().split())

def make_divisors(n):
    divisors_1 = []
    divisors_2 = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors_1.append(i)
            if i != n // i:
                divisors_2.append(n//i)
    divisors_1.extend(divisors_2[::-1])
    # divisors.sort()
    return divisors_1

divisors = make_divisors(M)
idx = bisect.bisect_right(divisors,int(M/N)) - 1
print(divisors[idx])

Measured memory_bytes: 38768
#include <stdio.h>

int main(void) {
    char S[10];
    scanf("%s", S);
    char yaki[5] = "YAKI";
    for(int i=0; i<4; i++){
        if(S[i]-yaki[i]){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>

using namespace std;

int main() {
	int N;
	double ans;
	double tmp = 0;
	double A[100];
	cin >> N;
	for (int i = 0; i < N; i++)cin >> A[i], tmp += (1.0 / A[i]);
	ans = 1.0 / tmp;
	cout << setprecision(10) << ans << endl;
	return 0;
}

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

int N, Q;
vector<vector<int>> G;
vector<long long> A;
vector<long long> ans;
vector<bool> seen;

void dfs(int now, int cnt){
    seen[now] = true;
    cnt += A[now];
    ans[now] += cnt;
    for(auto v : G[now]){
        if(seen[v])continue;
        dfs(v, cnt);
    }
    return;
}

int main(){
    cin >> N >> Q;
    G.assign(N, vector<int>());
    A.assign(N, 0);
    ans.assign(N, 0);
    seen.assign(N, false);
    for(int i = 1; i < N; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i = 0; i < Q; i++){
        long long p, x;
        cin >> p >> x;
        p--;
        A[p] += x;
    }
    
    dfs(0, 0);
    
    for(auto v : ans)cout << v << endl;
    return 0;
}

Measured memory_bytes: 25856
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
const long long inf=1e9+7;
const long long mod=1e9+7;
const int64_t CYCLES_PER_SEC=2800000000;
//
inline uint32_t Xor128(){
	static uint32_t x=123456789;
	static uint32_t y=362436069;
	static uint32_t z=521288629;
	static uint32_t w=88675123;
	uint32_t t=x^(x<<11);
	x=y;y=z;z=w;
	return w=(w^(w>>19))^(t^(t>>8));
}
struct Timer{
	int64_t start;
	Timer(){reset();}
	void reset(){start=getcycle();}
	void plus(double a){start-=(a*CYCLES_PER_SEC);}
	inline double get(){return (double)(getcycle()-start)/CYCLES_PER_SEC;}
	inline int64_t getcycle(){
		uint32_t low,high;
		__asm__ volatile ("rdtsc":"=a"(low),"=d"(high));
		return ((int64_t)low)|((int64_t)high<<32);
	}
};
//
int main(){
	int ma,da,mb,db;
	cin>>ma>>da>>mb>>db;
	if(ma!=mb){
		cout<<1<<endl;
	}else{
		cout<<0<<endl;
	}
	return 0;
}

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

long long a, b;
int main()
{
	std::cin >> a >> b;

	long long ans = 0;
	long long start = a;
	if (a % 2 == 1) {
		ans ^= a;
		start = a + 1;
	}

	if (b % 2 == 0) {
		ans ^= b;
		if (((b - 1 - start + 1) / 2) % 2 == 1)
			ans ^= 1;
	}
	else {
		if (((b - start + 1) / 2) % 2 == 1)
			ans ^= 1;
	}

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


Measured memory_bytes: 256
s = input()
if s[0] == "R":
    if s[1] == "R":
        if s[2] == "R":
            print("3")
        else:
            print("2")
    else:
        print("1")
            
elif s[1] == "R":
    if s[2] == "R":
        print("2")
    else:
        print("1")
elif s[2] == "R":
        print("1")
else:
    print("0")

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

namespace ABC88D
{
    class Program
    {
        static int[] currentInt = { 7, 5, 3, 0, 0, 0, 0, 0,0,0 };

        static long n
        {
            get
            {
                long ans = 0;
                for (int i = 0; i < currentInt.Length; i++)
                {
                    ans += currentInt[i] * (long)Math.Pow(10, i);
                }
                return ans;
            }
        }
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            if (N < 357) {
                Console.WriteLine(0);
                return;
            }
            int count = 1;

            Dictionary<int, int> number357 = new Dictionary<int, int> {
                {3,1 },
                {5,1 },
                {7,1 }
            };

            while (true)
            {
                bool plus1 = true;
                for (int i = 0; i <=currentInt.Length; i++)
                {
                    plus1 = false;
                    if (currentInt[i] == 0)
                    {
                        currentInt[i] = 3;
                        number357[3]++;
                    }
                    else if (currentInt[i] == 3)
                    {
                        number357[3]--;
                        number357[5]++;

                        currentInt[i] = 5;
                    }
                    else if (currentInt[i] == 5)
                    {
                        number357[5]--;
                        number357[7]++;
                        currentInt[i] = 7;
                    }
                    else
                    {
                        number357[7]--;
                        number357[3]++;
                        currentInt[i] = 3;
                        plus1 = true;
                    }
                    if (!plus1) break;
                }
                if (n <= N)
                {
                    if (number357[3] != 0 && number357[5] != 0 && number357[7] != 0)
                    {
                        //Console.WriteLine(n);
                        count++;
                    }

                }
                else break;
            }

            Console.WriteLine(count);
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 13268
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

    // test
    
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        @SuppressWarnings("unchecked")
        List<LR> list[] = new List[m + 1];
        for (int i = 1; i <= m; i++) {
            list[i] = new ArrayList<>();
        }
        for (int i = 1; i < n + 1; i++) {
            st = new StringTokenizer(in.readLine());
            int start = Integer.parseInt(st.nextToken());
            int end = Integer.parseInt(st.nextToken());
            list[end - start + 1].add(new LR(start, end));
        }
        int[] fen = new int[m + 1];
        int accum = n;
        for (int i = 1; i < m + 1; i++) {
            int ans = 0;
            for (int j = i; j < m + 1; j += i) {
                ans += accum(fen, j);
            }
            for (LR temp : list[i]) {
                add(temp.l, 1, fen);
                add(temp.r + 1, -1, fen);
            }
            System.out.println(ans + accum);
            accum -= list[i].size();
        }
    }

    static class LR {
        final int l, r;

        LR(int start, int end) {
            this.l = start;
            this.r = end;
        }
    }

    static int accum(int[] fen, int i) {
        int ans = 0;
        while (i > 0) {
            ans += fen[i];
            i -= (i & -i);
        }
        return ans;
    }

    static void add(int i, int a, int[] fen) {
        while (i < fen.length) {
            fen[i] += a;
            i += (i & -i);
        }
    }
}

Measured memory_bytes: 64060
import heapq

X, Y, Z, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

# (sum, idx of a, b, c)

h = []
heapq.heappush(h, (-A[0]-B[0]-C[0], 0, 0, 0))

ans = []
st = set()

for _ in range(K):
    s, i, j, k = heapq.heappop(h)
    ans.append(-s)
    if i+1 < X and not((i+1, j, k) in st):
        heapq.heappush(h, (-A[i+1]-B[j]-C[k], i+1, j, k))
        st.add((i+1, j, k))
    if j+1 < Y and not((i, j+1, k) in st):
        heapq.heappush(h, (-A[i]-B[j+1]-C[k], i, j+1, k))
        st.add((i, j+1, k))
    if k+1 < Z and not((i, j, k+1) in st):
        heapq.heappush(h, (-A[i]-B[j]-C[k+1], i, j, k+1))
        st.add((i, j, k+1))

for v in ans:
    print(v)


Measured memory_bytes: 5104
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

//---------- 約数列挙 ----------
vector<int> yakusu(int n)
{
	vector<int> v;
	for (int i = 1; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			v.push_back(i);
			if (i != n / i)
			{
				v.push_back(n / i);
			}
		}
	}
	sort(v.begin(), v.end());
	return v;
}

//---------- 最大公約数 ----------
int gcd(int x, int y)
{
	int r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}

int N;
int A[1000001];

bool flg[1000001];

bool IsPairwise()
{
	for (int i = 0; i < N; i++)
	{
		if (flg[A[i]]) return false;

		auto yaku = yakusu(A[i]);
		for (int j = yaku.size() - 1; j >= 1; j--)
		{
			int y = yaku[j];
			if (flg[y]) return false;

			int cur = y;
			while (true)
			{
				flg[cur] = true;
				cur += y;
				if (cur > 1000000) break;
				
			}
		}
	}

	return true;
}


bool IsSetWize()
{
	int g = A[0];
	for (int i = 1; i < N; i++)
	{
		g = gcd(g, A[i]);
	}
	return g == 1;
}


signed main()
{
	cin >> N;
	REP(i, N)
	{
		cin >> A[i];
	}

	ARY_SORT(A, N);
	ARY_REVERSE(A, N);

	if (IsPairwise())
	{
		cout << "pairwise coprime" << endl;
	}
	else if (IsSetWize())
	{
		cout << "setwise coprime" << endl;
	}
	else
	{
		cout << "not coprime" << endl;
	}
}



Measured memory_bytes: 12364
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N;
  cin>>N;
  ll a[N];
  vl b(100010,0);
  rep(i,N){
    cin>>a[i];
    b[a[i]]++;
  }
  ll ans=b[0]+b[1]+b[2];
  ll cnt=ans;
  for(int i=3;i<100010;i++){
    cnt-=b[i-3];
    cnt+=b[i];
    ans=max(cnt,ans);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4840
N,A,B=input().split()
N=int(N)
A=int(A)
B=int(B)

def findSumOfDigits(n):
    k = 0
    sum = 0
    while n>0:
        k = n%10
        n = n//10
        sum = sum + k
    return sum

sum=0
for i in range(N+1):
    tmp = findSumOfDigits(i)
    if A<=tmp:
        if tmp<=B:
            sum = sum + i
print(sum)


Measured memory_bytes: 8948
#include <iostream> pre processor directive
#include <string>
#include <iomanip>
#include <cctype>
using namespace std;
int main()
{
    int A,B;
    cin>>A>>B;
    if(A==1 || B==1){
        if(A==B){cout<<"Draw"<<endl; return 0;}
        else{
            if(A==1){cout<<"Alice"<<endl; return 0;}
            else{cout<<"Bob"<<endl;return 0;}
        }
    }
    else{
        if(A>B){cout<<"Alice"<<endl;}
        else if(B>A){cout<<"Bob"<<endl;}
        else{cout<<"Draw"<<endl;}
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <queue>
#include <map>
using namespace std;
#define pb          emplace_back
#define fi          first
#define se          second
#define show(...)   fprintf(stderr, __VA_ARGS__ )
#define outl(x)     cout << (x) << '\n'
#define rep(i,n)    for(int i=0; i<(n); ++i)
#define inside(x,y,w,h) ((x)>=0 && (y)>=0 && (x)<(w) && (y)<(h))
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
constexpr int       INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int dx[] = {1, 0, -1, 0};
constexpr int dy[] = {0, 1, 0, -1};


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

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

    int d = b -a;

    int sum = 0;
    for (int i=1; i <=d; ++i) {
        sum += i;
    }

    outl(sum- b);


}



Measured memory_bytes: 256
# https://atcoder.jp/contests/abc116/tasks/abc116_d
class PopHeap
  attr_accessor :nodes, :size
  def initialize
    @nodes = []
    @size = 0
  end

  def push(x)
    current_index = @size
    @size += 1
    while current_index > 0 do
      parent_index = (current_index - 1)>>1
      parent_value = @nodes[parent_index]
      break if parent_value <= x
      @nodes[current_index] = parent_value
      current_index = parent_index
    end
    @nodes[current_index] = x
  end

  def pop
    top = @nodes[0]
    current_node_index = 0
    current_node_value = @nodes[0] = @nodes[@size - 1]
    @nodes[@size - 1] = nil
    @size -= 1

    while
      child_node_index_r = (current_node_index + 1) << 1
      child_node_index_l = child_node_index_r - 1
      return top unless child_node_index_l < @size
      child_node_value_l = @nodes[child_node_index_l]
      child_node_value_r = @nodes[child_node_index_r]
      if child_node_value_r&.<child_node_value_l
        min_child_value = child_node_value_r
        min_child_index = child_node_index_r
      else
        min_child_value = child_node_value_l
        min_child_index = child_node_index_l
      end
      return top unless min_child_value < current_node_value
      change(current_node_index, min_child_index)
      current_node_index = min_child_index
    end
  end

  private

  def change(index_i, index_j)
    @nodes[index_i], @nodes[index_j] = @nodes[index_j], @nodes[index_i]
  end
end

N, K = gets.split.map(&:to_i)
max_in_type = {}
values = []

N.times do
  temp = gets.split.map(&:to_i)
  max_in_type[temp[0]] = temp[1] if !(max_in_type[temp[0]]&.>(temp[1]))
  values << (temp[1] << 17) + temp[0]
end

ph = PopHeap.new
sum = 0
use_type_count = 0
type_flags = {}

t_mask = (1 << 17) - 1

values.sort.reverse[0...K].each do |t_v|
  t = t_v & t_mask
  v = t_v >> 17
  sum += v
  if !type_flags[t]
    type_flags[t] = true
    use_type_count += 1
  else
    ph.push(v)
  end
end
ans = sum + use_type_count**2

rph = max_in_type.select { |t, v| !type_flags[t] }.values.sort.reverse

t = 0
phsize = ph.size
rphsize = rph.size
(phsize > rphsize ? rphsize : phsize).times do |i|
  sum = sum - ph.pop + rph[i]
  t = sum + (use_type_count += 1)**2
  ans = t if t > ans
end

p ans

Measured memory_bytes: 20328
n = gets.to_i
a = $<.map(&:to_i).sort.reverse

def f(a, select, max)
	return if max >= $best
	if a.empty?
		$best = max if max < $best
		return
	end
	
	k = a[0]
	[k, select.size].min.downto(1){|r|
		(1..max).to_a.combination(r){|b|
			if check(select, b)			
				f(a[1..-1], select + [b + (max+1..max+k-r).to_a], max+k-r)
			end
		}
	}
	f(a[1..-1], select + [(max+1..max+k).to_a], max+k)
end

def check(select, a)
	select.all?{|b| (b & a).size <= 1}
end

s = 0
(0..n-1).each{|i|
	if a[i] > n-1
		s += a[i]-n+1
		a[i] = n-1
	end
}

$best = Float::INFINITY
f(a, [], 0)
p s + $best

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

int main(){
     string A, B, C;
     cin >> A >> B >> C;

  if(A.at(A.size()-1) == B.at(0) && B.at(B.size()-1) == C.at(0)) cout << "YES";
  else cout << "NO";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 2010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    vector<ll> a(n+1);
    rep(i,n) cin >> a[i+1];
    rep(i,n) a[i+1] += a[i];
    map<ll,ll> cnt;
    vector<ll> mod;
    rep(i,n+1){
        cnt[a[i]%m]++;
        mod.push_back(a[i]%m);
    }
    SORT(mod);
    mod.erase(unique(all(mod)),mod.end());
    ll ans = 0;
    for(ll i:mod){
        ans += cnt[i]*(cnt[i]-1)/2;
    }
    PRINT(ans);
}


Measured memory_bytes: 6008
X = int(input())
#X = 999

max = 1
if X != 1:
    for b in range(2,X):
        y = 0
        p = 2
        while 1:
            pre_y = y
            y = pow(b,p)
            p += 1
            if y > X:
                if pre_y > max:
                    max = pre_y
                break
print(max)


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

int main() {
  vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << a[k-1] << endl;
  return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
const int INF = 1e18;

const int MOD = 1e9+7;
// const int MOD = 998244353;
const int MAX = 2000050;
int 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;
    }
}

//nCkを求める
int 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;
}

//ModInt
template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
  
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
  
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};
using mint = ModInt<MOD>;


signed main(){
	COMinit();
    int k; string s; cin >> k >> s;
    mint ans = pow((mint)26,k+SZ(s));
    //部分文字列にs含まないのを引く
    mint dis = 0;
    int M = k+SZ(s);
	REP(i,SZ(s)){
        dis += (mint)COM(M,i) * pow((mint)25,M-i);
    }
    ans -= dis;
    cout << ans << endl;
}

Measured memory_bytes: 52140
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}
 
void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n, vector<int>());
    vector<int> d(n, 0);
    int x, y;
    REP(i, m) {
        cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        d[y]++;
    }

    vector<int> s;
    REP(i, n) if (d[i] == 0) s.push_back(i);

    vector<int> memo(n, -1);
    function<int(int)> dfs = [&](int c) {
        if (memo[c] != -1) return memo[c];
        int mx = 0;
        for (auto x: g[c]) {
            chmax(mx, dfs(x) + 1);
        }
        return memo[c] = mx;
    };

    int ans = 0;
    for (auto q : s) chmax(ans, dfs(q));
    cout << ans << EOL;
}


Measured memory_bytes: 12800
#include<cstdio>
#include<cstdlib>
using namespace std;
int main(){
	int a,b,c,x,ans=0,t;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				t=500*i+100*j+50*k;
				if(t==x) ans++;
			}
		}
	}
	printf("%d",ans);
	return 0;
} 

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    for i in range(2):
        if S[i] != S[i+1]:
            return "Yes"
    return "No"


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    print(solve(S))

if __name__ == '__main__':
    main()


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




int main(){
  int n,m;
  cin>>n>>m;
  int a[10000],b[10000],ans[10000]={};
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int count=0,mx;
for(int i=0;i<m;i++){
    cin>>b[i];
    for(int t=0;t<n;t++){
      if(a[t]<=b[i]){ans[t]++; if(ans[t]>count){count=ans[t]; mx=t;} break;}
    }
  }

 cout<<mx+1<<endl;
    
  return 0;
}



Measured memory_bytes: 3148
import sys

# sys.stdin = open("a1.in")


x, y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

if x in a:
    gx = 1
if x in b:
    gx = 2
if x in c:
    gx = 3
if y in a:
    gy = 1
if y in b:
    gy = 2
if y in c:
    gy = 3

if gx == gy:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

struct data_t {
	string name;
	double eff;

	bool operator<(const data_t& right) const {
		if (eff == right.eff) {
			return (name < right.name);
		}
		else {
			return (eff > right.eff);
		}
	}
};

int main(void) {
	int N;
	while (cin >> N, N) {
		vector<data_t> data(N);
		int p,temp,d,e,f,m,s;
		for (int i = 0; i < N; ++i) {
			cin >> data[i].name;
			cin >> p; 
			int time = 0;
			for (int i = 'A'; i <= 'C'; ++i) {
				cin >> temp;
				time += temp;
			}
			cin >> d >> e >> f >> s >> m;
			time += m * (d + e);
			data[i].eff = (double)((f * m * s) - p)/(double)time;
		}

		sort(data.begin(),data.end());

		for (int i = 0; i < N; ++i) {
			cout << data[i].name << endl;
		}
		cout << "#" << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

ll dp[101][100001];

int main(){
    int N, W;
    int w[101], v[101];
    cin >> N >> W;
    for(int i=1;i<=N;i++){
        cin >> w[i];
        cin >> v[i];
    }
    for(int i=0;i<=N;i++) dp[i][0] = 0;
    for(int j=0;j<=W;j++) dp[0][j] = 0;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=W;j++){
            if(w[i] <= j) dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
            else dp[i][j] = dp[i-1][j];
        }
    }

    cout << dp[N][W] << endl;
    
    return 0;
}

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

using namespace std;

#define ll long long

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(n);
    for(int i=0; i<m; i++) cin >> a[i];

    for(int i=0; i<m; i++) n -= a[i];
    cout << max(n, -1) << endl;
    return 0;
}

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

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;}

const ll INF = 1LL << 60;

int main(){
  string s;
  cin >> s;
  if(s.size()==2){
    cout << s  << endl;
  }else{
    reverse(s.begin(),s.end());
    cout << s << endl;
  }
}


Measured memory_bytes: 256
N, M = gets.split(" ").map(&:to_i)
ary = Array.new(N) {Array.new}
count = 0
H = gets.split(" ").map(&:to_i)
M.times do 
    a, b =  gets.split(" ").map(&:to_i)
    ary[a - 1] << H[b - 1]
    ary[b - 1] << H[a - 1]
end

N.times do |i|
    if ary[i] == [] || H[i] > ary[i].max
        count += 1
    end
end
puts count

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

//--A--------B
//------C--D

//-----A----------B
//--C--------D


int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int res = 0;
	if (a <= c) {
		if (c <= b) {
			if (d <= b) res = d - c;
			else res = b - c;
		}
	}

	if (c <= a) {
		if (a <= d) {
			if (b <= d) res = b - a;
			else	res = d - a;
		}
	}

	cout << res << endl;
	//cin >> a;
}

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

int main() {
    cin.tie(NULL);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string s;
    map<string,int> m;
    int ma=1;
    while(n--){
        cin>>s;
        m[s]++;
        ma=max(ma,m[s]);
    }
    for(auto i:m){
        if(i.second==ma)cout<<i.first<<endl;
    }
    return 0;
}

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

unordered_map<int, vector<int>> edge;

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    bool ok[n + 1];
    for (int i = 1; i <= n; i++)
    {
        ok[i] = false;
    }
    for (int i = 0; i < m; i++)
    {
        int a, b;
        scanf("%d %d", &a, &b);

        if (a == 1)
        {
            if (ok[b])
            {
                cout << "POSSIBLE" << endl;
                return 0;
            }
            ok[b] = true;
        }
        if (b == n)
        {
            if (ok[a])
            {
                cout << "POSSIBLE" << endl;
                return 0;
            }
            ok[a] = true;
        }
    }

    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 384
n = gets.chomp.to_i
l = gets.chomp.split.map(&:to_i)

l.sort!
ans = 0

(0...n-1).each do |ai|
  (ai+1...n-1).each do |bi| 
    a,b = l[ai],l[bi]
    ci = l.bsearch_index{|c| c >= a+b}
    if ci.nil?
      ans += n - 1 - bi
    else
      ans += ci - 1 - bi
    end
  end
end

puts ans


Measured memory_bytes: 1788
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int ll;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
ll powmod(ll a, ll b) {
    ll res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
int nxt() {
    int x;
    scanf("%d", &x);
    return x;
}

const int nax = 10123;
char k[nax];
void add_self(int &a, int b) {
    a += b;
    if (a >= mod) {
        a -= mod;
    }
}

int main() {
    scanf("%s", k);
    int D = nxt();
    int len = strlen(k);
    VVI dp(D, VI(2));
    dp[0][0] = 1;
    for (int where = 0; where < len; where++) {
        VVI new_dp(D, VI(2));
        for (int sum = 0; sum < D; sum++) {
            for (bool sm_already : {false, true}) {
                for (int digit = 0; digit < 10; digit++) {
                    if (digit > k[where] - '0' && !sm_already) break;
                    add_self(new_dp[(sum + digit) % D][sm_already || (digit < k[where] - '0')],
                             dp[sum][sm_already]);
                }
            }
        }
        dp = new_dp;
    }
    int answer = (dp[0][false] + dp[0][true]) % mod;
    answer--;
    if (answer == -1) answer = mod - 1;
    printf("%d\n", answer);
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  
  vector<int> s=a;
  sort(s.rbegin(), s.rend());
  rep(i,n){
    if (a.at(i) == s[0]) {
      cout << s[1] << endl;
      continue;
    }
    
    cout << s[0] << endl;
  }
}


Measured memory_bytes: 3200
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
	try{
	    BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
	    String st;
	    while((st=sc.readLine())!=null){
		long sum=0, d = Integer.valueOf(st);
		for(int i=1; i<600/d; i++)
		    sum+=d*(i*d)*i*d;
		System.out.println(sum);
	    }
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 9360
import numpy as np
import math
a,b,x = map(int,input().split())
c = x/a
ans = np.pi/2-math.atan(c*2/b**2)


if round(math.tan(ans)*a,3) < b:
    ans = math.atan(2*(a*b-c)/a**2)
print(180/np.pi*ans)

Measured memory_bytes: 12504
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int h[n+1];
  for(int i=1;i<=n;i++) cin>>h[i];
  int dp[n+1];
  dp[1]=0;
  dp[2]=abs(h[1]-h[2]);
  for(int i=3;i<=n;i++) dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
  cout<<dp[n];
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  string S;
  cin >> S;
  int ans = 700;
  REP(i, 3) {
    if (S.at(i) == 'o') {
      ans += 100;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
#define inf 0x3f3f3f3f
#define N 100010
using namespace std;

int main(){
	int x;
	scanf("%d",&x);
	if(x>=30)
        printf("Yes\n");
    else
        printf("No\n");
	return 0;
}


Measured memory_bytes: 3744
import sys

input=sys.stdin.readline

N,M=map(int,input().split())
X=list(map(int,input().split()))

dic={}
for i in range(N):
    if not X[i] in dic:
        dic[X[i]]=0
    dic[X[i]]+=1

table=[[0,0] for i in range(0,M)]
for key in dic.keys():
    q=dic[key]//2
    r=dic[key]%2
    table[key%M][0]+=q
    table[key%M][1]+=r

ans=table[0][0]+table[0][1]//2
for i in range(1,M//2+1):
    if 2*i!=M:
        a,b=table[i]
        c,d=table[M-i]
        if b>=d:
            ans+=a+d+c+min((b-d)//2,c)
        else:
            ans+=a+b+c+min((d-b)//2,a)
    else:
        ans+=table[i][0]+table[i][1]//2

print(ans)


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

int main(void) {
  int N;
  cin >> N;
  map<string, int> list;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    list[S] += 1;
  }
  int max = 0;
  for (const auto& x : list) {
    if (max < x.second) {
      int v = x.second;
      max = v;
    }
  }
  for (auto itr = list.begin(); itr != list.end(); itr++) {
    if (itr->second == max) {
      cout << itr->first << endl;
    }
  }
}

Measured memory_bytes: 19224
#include <stdio.h>
int main()
{
    int n;  scanf("%d", &n);
    int arr[55]={0};
    for(int i=0; i<n; i++)
        scanf("%d", &arr[i]);
    int ans = 0;
    for(int i=0; i<n; i++)
        for(int j=i+1; j<n; j++)
            ans += arr[i]*arr[j];
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>

using namespace std;

typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;

typedef vector<lint> vl;
typedef pair<lint,lint> pll;


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

    string s, t; cin>>s>>t;
    //if (t.sub)
    t.resize(t.size()-1);
    if (t == s) cout<<"Yes\n";
    else cout<<"No\n";
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)

typedef long long ll;

int main() {
    int N;
    cin >> N;
    int Q = N / 1000;
    int R = N % 1000;

    if (R == 0) {
        cout << "0" << endl;
    } else {
        cout << (1000 - R) << endl;
    }

    return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
 double n ; cin>>n ;
  cout << fixed << setprecision(10);
  ll a=n;
 if(a%2==0) cout<< 0.50000000  <<endl;
  else cout<< (a/2+1.0)/n<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <set>
#include <stack>

using namespace std;

template<typename T>inline T get(){T x;cin>>x;return x;}

int main()
{
    map<int,vector<int>> xindex;
    map<int,vector<int>> yindex;

    int n = get<int>();
    vector<int> a(n), b(n);
    vector<bool> visited(n);
    for (int i = 0; i < n; i++) {
        a[i] = get<int>(), b[i] = get<int>();
        xindex[a[i]].push_back(i);
        yindex[b[i]].push_back(i);
    }
    long ans = 0;
    for (int i = 0; i < n; i++) {
        if (visited[i]) continue;

        vector<int> xset;
        vector<int> yset;
        function<long(int)> dfs = [&](int j) {
            if (visited[j]) return 0L;
            xset.push_back(a[j]);
            yset.push_back(b[j]);
            visited[j] = true;
            long r = 1;
            for (int k : xindex[a[j]])
                r += dfs(k);
            for (int k : yindex[b[j]])
                r += dfs(k);
            return r;
        };
        long r = dfs(i);
        sort(xset.begin(), xset.end());
        long xsize = unique(xset.begin(), xset.end()) - xset.begin();
        sort(yset.begin(), yset.end());
        long ysize = unique(yset.begin(), yset.end()) - yset.begin();
        ans += xsize*ysize - r;
    }
    cout << ans << endl;
    return 0;
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  t.pop_back();
  cout << (s == t ? "Yes\n" : "No\n");
}


Measured memory_bytes: 3616
n=[int(i) for i in input().split()]
array=[]
for i in range(n[0]):
  array.append(n[1])
for i in range(n[2]):
  array[int(input())-1]+=1
for i in range(n[0]):
  array[i]-=n[2]
  if(array[i]<=0):
    print("No")
  else:
    print("Yes")

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

#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())

#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 int;
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>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template <class T>
inline T sqr(T x) { return x * x; }

void solve()
{
    int n;
    cin >> n;
    VI a(3 * n);
    REP(i, 0, 3 * n)
    cin >> a[i];
    priority_queue<int> lq, rq;
    VLL ru(3 * n + 1);
    REP(i, 0, 3 * n)
    ru[i + 1] = ru[i] + a[i];
    VLL lsum(n + 1), rsum(n + 1);

    lsum[0] = 0;
    REP(i, 0, n)
    lq.push(-a[i]);
    REP(i, 1, n + 1)
    {
        lq.push(-a[n + i - 1]);
        int v = lq.top();
        lq.pop();
        lsum[i] = lsum[i - 1] - v;
    }

    rsum[0] = 0;
    REP(i, 0, n)
    rq.push(a[3 * n - i - 1]);
    REP(i, 1, n + 1)
    {
        rq.push(a[2 * n - i]);
        int v = rq.top();
        rq.pop();
        rsum[i] = rsum[i - 1] + v;
    }

    LL ans = ru[n] - (ru[3 * n] - ru[n] - rsum[n]);
    REP(i, 0, n + 1)
    {
        LL tmp = (ru[n + i] - lsum[i]) - (ru[3 * n] - ru[n + i] - rsum[n - i]);
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

int main()
{
    solve();

    return 0;
}

Measured memory_bytes: 6520
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
using ll = long long;
int main(){ 
    ll n;
    cin>>n;
    vector<double> a(n);
    rep(i,n) cin>>a[i];
    sort(a.begin(),a.end());
    double b=a[0];
    rep(i,n-1){
        b=(a[i+1]+b)/2;
    }
    cout<<b;
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

#define max 100
#define a 0
#define b 1
#define c 2
#define inf (1<<21)

int n, m[max][max];

void D(){
  int i, v, min;
  int d[max], ch[max];
  for(i=0 ; i<n ; i++){
  d[i]=inf;
  ch[i]=a;
  }
  d[0]=0;
  ch[0]=b;
  while(1){
    min=inf;
    int u=-1;
    for(i=0 ; i<n ; i++){
      if(min>d[i] && ch[i]!=c){
        u=i;
        min=d[i];
      }
    }
    if(u==-1)break;
    ch[u]=c;
    for(v=0 ; v<n ; v++){
      if(ch[v]!=c && m[u][v]!=inf){
        if(d[v]>d[u]+m[u][v]){
          d[v]=d[u]+m[u][v];
          ch[v]=b;
        }
      }
    }
  }
  for(i=0 ; i<n ; i++){
  if(d[i]!=inf)printf("%d %d\n", i, d[i]);
  else printf("%d -1\n",i);
  }
}

int main(){
  int i, j, u, k, v, num;
  scanf("%d", &n);
  for(i=0 ; i<n ; i++){
    for(j=0 ; j<n ; j++){
      m[i][j]=inf;
    }
  }
  for(i=0 ; i<n ; i++){
    scanf("%d%d", &u, &k);
    for(j=0 ; j<k ; j++){
      scanf("%d%d", &v, &num);
      m[u][v]=num;
    }
  }
  D();
  return 0;
}



Measured memory_bytes: 2060
#include<iostream>
#include<algorithm>

using namespace std;

long long A[200000];

struct work
{
    int times;
    long long num;
};
work B[200000];

bool cmp(const work&a, const work&b)
{
    return a.num>b.num;
}

int main()
{
    int n, m;
    long long sum;

    cin>>n>>m;

    for(int i=0;i<n;i++)
        cin>>A[i];
    for(int i=0;i<m;i++)
        cin>>B[i].times>>B[i].num;
    sort(A,A+n);
    sort(B,B+m,cmp);
    sum=0;
    int i, j, ans;
    i = 0;
    j = 0;
    ans = 0;
    while(i<n)
    {
        
        if(A[i] < B[j].num)
        {
            if(ans==B[j].times)
            {
                j++;
                ans = 0;
                continue;
            }
            ans++;
            sum += B[j].num;
        }
        else
        {
            sum += A[i];
        }
        i++;
    }
    cout<<sum;
}

Measured memory_bytes: 3840
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <queue>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#define ll long long
using namespace std;
const int maxn=1e5+111;
int a[2000];
int main(){
    int n,m;
	scanf("%d%d",&n,&m);
	int sum=0;
	for(int i=1;i<=n;++i){
		scanf("%d",a+i);
		sum+=a[i];
	}
	sort(a+1,a+1+n,[](int a,int b){return a>b;});
	int minn=a[m];
	if(a[m]*4*m>=sum) puts("Yes");
	else puts("No");
    return 0;
}

Measured memory_bytes: 256
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
T = [int(input()) for _ in range(D)]

res = 0
last = [0 for _ in range(26)]

for d in range(D):
    res += S[d][T[d] - 1]
    last[T[d] - 1] = d + 1
    for j in range(26):
        res -= C[j] * ((d + 1) - last[j])
    print(res)

Measured memory_bytes: 9248
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
    }
    println!("{}", 6 - a - b)
}


Measured memory_bytes: 4352
function main()
  
  (N,K) = map(x -> parse(Int,x), split(readline()))
  
  k = zeros(Int,K)

  for i in 1:K

    if i == K && K != 1
      k[i] = N
    else
      k[i] = 1
      N -= 1
    end
    
  end
  
  println(k[end]-1)
  
end

main()

Measured memory_bytes: 109768
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){

  int n, l;
  string s[100];
  cin >> n >> l;

  for(int i=0; i<n; i++){
    cin >> s[i];
  }

  sort(s, s+n);

  for(int i=0; i<n; i++)
    cout << s[i];
    cout << endl;

  return 0;
}

Measured memory_bytes: 256