akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n;
vector<int> cnt(3, 0);
double dp[330][330][330];

double rec(int c1, int c2, int c3) {
    if(c1 == 0 && c2 == 0 && c3 == 0) return 0.0;
    if(dp[c1][c2][c3]  >= 0.0) return dp[c1][c2][c3];
    double res = (double)n;
    if(c1 > 0) res += rec(c1-1, c2, c3) * (double)c1;
    if(c2 > 0) res += rec(c1+1, c2-1, c3) * (double)c2;
    if(c3 > 0) res += rec(c1, c2+1, c3-1) * (double)c3;
    double z = (double)(c1+c2+c3);
    res *= 1.0/z;
    return dp[c1][c2][c3] = res;
}

int main() {
    cin >> n;
    for(int i = 0; i < n; ++i) {
        int a; cin >> a; a--;
        cnt.at(a)++;
    }
    for(int i = 0; i <= n; ++i) {
        for(int j = 0; j <= n; ++j) {
            for(int k = 0; k <= n; ++k) {
                dp[i][j][k] = -1.0;
            }
        }
    }
    double ans = rec(cnt.at(0), cnt.at(1), cnt.at(2));
    printf("%.14f\n", ans);
}

Measured memory_bytes: 258176
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
  ll N,M;
  cin>>N>>M;
  vector<bool> vec(N);
  vector<ll> kosuu(N);
  vec.at(0)=true;
  for(ll i=0;i<N;i++){kosuu.at(i)=1;}
  for(ll i=0;i<M;i++){
    ll a,b;
    cin>>a>>b;
    if(vec.at(a-1) && kosuu.at(a-1)>1){vec.at(b-1)=true;}
    if(vec.at(a-1) && kosuu.at(a-1)==1){vec.at(b-1)=true;vec.at(a-1)=false;}
    kosuu.at(a-1)--;
    kosuu.at(b-1)++;
  }
  ll ans=0;
  for(ll i=0;i<N;i++){
    if(vec.at(i) && kosuu.at(i)>0){ans++;}
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
$a=[]
rootID=0
class Tree
    attr_accessor :id, :parent, :children
    def initialize(id, children)
        @id = id
        @parent = -1
        @children = children
    end

    def preorder
        print ' ', id
        $a[children[0]].preorder unless children[0] == -1
        $a[children[1]].preorder unless children[1] == -1
    end

    def inorder
        $a[children[0]].inorder unless children[0] == -1
        print ' ', id
        $a[children[1]].inorder unless children[1] == -1
    end

    def postorder
        $a[children[0]].postorder unless children[0] == -1
        $a[children[1]].postorder unless children[1] == -1
        print ' ', id
    end
end

N = gets.to_i

N.times {
    id, *children = gets.split.map(&:to_i)
    $a << Tree.new(id, children)
}
$a.sort_by! {|e| e.id}
$a.each {|ele|
    ele.children.each {|e| $a[e].parent = ele.id unless e == -1}
}
$a.each {|e| rootID = e.id if e.parent == -1}

puts 'Preorder'
$a[rootID].preorder
puts '', 'Inorder'
$a[rootID].inorder
puts '', 'Postorder'
$a[rootID].postorder
puts

Measured memory_bytes: 6124
/*
 ***
 Question Name:
 ***
 Question Link:
 ***
 Idea:
 */

#include <memory.h>
#include <ctime>
#include <random>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef unordered_set<int> ui;
typedef pair<LL,LL> pLL;

class FourColoring{
    vector<string> Templ= {"RY","BG"};
public:
    void solve(int H,int M, int d){
        for(int i=0;i<H;++i){
            for(int j=0;j<M;++j) cout<<Templ[((i+j+H+M)/d)%2][((i-j+H+M)/d)%2];
            cout<<endl;
        }
    }
};

int main(){
    int H,M,d;
    cin>>H>>M>>d;
    FourColoring().solve(H, M, d);
    return 0;
}

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

int main () {

    long long N;
    cin >> N;

    long long ans = 10000000000000;
    for (long long a = 1; a*a <= N; a++) {
        long long b = N/a;
        if (a*b == N) {
            ans = min(ans, a+b-2);
        }
    }
    cout << ans << endl;

    return 0;
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();


    ll n, m, k;
    cin>> n>> m>> k;

    if( k> n)
    {
        m= max( 0LL, m+ n-k );
        n= 0;
    }
    else
    n= n-k;


    // m= max (0LL , m+ min (0LL, n-k) );
    //n= max (0LL, n-k);


    cout << n <<" " <<m << '\n';

    return 0;
}



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

int main()
{
  int N, A, B;
  string S;
  cin >> N >> A >> B;
  cin >> S;
  
  int a = 0;
  int b = 0;
  
  for(int i = 0; i < N; ++i)
  {
    if(S[i] == 'a')
    {
      if(a+b<A+B)
      {
        cout << "Yes" << endl;
        a++;
      }
      else
      {
        cout << "No" << endl;
      }
    }
    else if(S[i] == 'b')
    {
      if(a+b<A+B && b+1<=B)
      {
        cout << "Yes" << endl;
        b++;
      }
      else
      {
        cout << "No" << endl;
      }
    }
    else if(S[i] == 'c')
    {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 3768
from fractions import gcd
def lcm(L):
    x = L[0]
    for i in range(1, len(L)):
        x = (x*L[i])//gcd(x, L[i])
    return x

n = int(input())
T = set()
ans = 1
for i in range(n):
    T.add(int(input()))
print(lcm(list(T)))

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n,q;
    string s;
    cin >> n;
    cin >> s;
    cin >> q;
    int k[q];
    rep(i,q){
        cin >> k[i];
    }
    rep(i,q){
        ll d = 0, m = 0, dm = 0;
        ll ans = 0;
        for(int right = 0; right < n; right++){
            if(s[right] == 'D'){
                d++;
            }else if(s[right] == 'M'){
                m++;
                dm += d;
            }else if(s[right] == 'C'){
                ans += dm;
            }
            int left = right - (k[i] - 1);
            if(left < 0) continue;
            if(s[left] == 'D'){
                d--;
                dm -= m;
            }else if(s[left] == 'M'){
                m--;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1412
function Main(input: string) {
  const lines = input.split('\n');
  const params1 = lines[0].split(' ');
  const params2 = lines[1].split(' ');

  const n = parseInt(params1[0]);
  const s = params2[0];

  let cnt = 0;
  for (let i = 0; i < n; i++) {
    const s1 = s.slice(0, i);
    const s2 = s.slice(i);
    
    let set1 = new Set();
    s1.split('')
      .forEach(x => {
        set1.add(x)
      });
    let set2 = new Set();
    s2.split('').forEach(x => {
      set2.add(x)
    });

    let tmp = 0;
    set1.forEach(x => {
      if (set2.has(x)) tmp++;
    });

    cnt = Math.max(cnt, tmp);
  }
  
  console.log(cnt);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7960
// p面体サイコロの期待値
// (p+1)/2 // 7なら4 // 6なら3.5

// 期待値の配列を用意
//   vector<int> exp(n);

// 連続するK個の合計期待値は、
// exp(0)+exp(1)+...+exp(K-1)
// から始まって、K-1=Nとなるまで、異なる選び方ができる

#include <bits/stdc++.h>
using namespace std;
 
int main() {

int K, N;
int num = 0;
cin >> N >> K;
vector<double> vec(N);

for (int i=0; i<N; i++) {
    cin >> num;
    vec.at(i) = ((double)num + 1)/2;
}

double sum = 0.0;
double maxExp = 0.0;
for(int i=0;i<K;i++){
  sum += vec.at(i);
}
maxExp = sum;

if(N>1){
  for(int i=0;i<N-K;i++){
    sum = sum - vec.at(i) + vec.at(i+K);
    if(sum > maxExp){
      maxExp = sum;
    }
  }
}

cout << fixed << setprecision(12) << maxExp << endl;
return 0;
}

Measured memory_bytes: 1792
//Back Tracking Method
#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e5 + 10;
vector<int> G[maxn];
int dp[maxn];                   //dp[i] := from the i-th vertex the longest path
int n, m, ans;

void dfs(int u) {
  if (dp[u]) return;
  for (auto x : G[u]) {
    dfs(x);
    dp[u] = max(dp[u], dp[x] + 1);
  }
  return;
}

int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    G[x].emplace_back(y);
  }
  for (int i = 1; i <= n; i++) {
    dfs(i);
    ans = max(ans, dp[i]);
  }
  cout << ans;
  return 0;
}



Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	
	int m;
	cin>>m;
	int arr[n][m];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			char temp;
			cin>>temp;
			if(temp=='.')
			{
				arr[i][j]=1;
			}
			else
				arr[i][j]=0;
		}
	}
	int dp[n][m];
	memset(dp,0,sizeof(dp));
	for(int i=0;i<n;i++)
	{
		if(arr[i][0]==1)
			dp[i][0]=1;
		else
			break;
	}
	for(int i=0;i<m;i++)
	{
		if(arr[0][i]==1)
			dp[0][i]=1;
		else
			break;
	}
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<m;j++)
		{
		    if(arr[i][j]!=0)
			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
		}
	}
// 	for(int i=0;i<n;i++)
// 	{
// 		for(int j=0;j<m;j++)
// 		{
// 			dp[i][j]=dp[i-1][j]+dp[i][j-1];
// 		}
// 	}
	cout<<dp[n-1][m-1]<<endl;
	return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

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

    int ans = 0;
    if(a + b <= 2 * c){
        ans = a * x + b * y;
    }else{
        if(x > y){
            ans += y * 2 * c;
            if(a <= 2 * c){
                ans += (x - y) * a;
            }else{
                ans += (x - y) * 2 * c;
            }
        }else{
            ans += x * 2 * c;
            if(b <= 2 * c){
                ans += (y - x) * b;
            }else{
                ans += (y - x) * 2 * c;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def main():
	bridge = [0 for i in range(4)]
	for i in range(3):
		a, b = map(int, input().split())
		bridge[a - 1] += 1
		bridge[b - 1] += 1
	m = max(bridge)
	if m == 3:
		print("NO")
	else:
		print("YES")

if __name__ == '__main__':
	main()

Measured memory_bytes: 2940
import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

# available on Google, not available on Codeforces
# import numpy as np
# import scipy


def solve(x):  # fix inputs here
    console("----- solving ------")

    res = defaultdict(set)
    for a in range(1, int(math.sqrt(x))):
        for b in range(1, int(math.sqrt(x - a*a))):
            for c in range(1, int(math.sqrt(x - a*a - b*b))):
                total = a**2 + b**2 + c**2 + a*b + b*c + a*c
                res[total].add(tuple(sorted([a,b,c])))

    for i in range(1,x+1):
        console(i, res[i])
        cnt = 0
        for a,b,c in res[i]:
            if a == b == c:
                cnt += 1
            elif a == b:
                cnt += 3
            elif b == c:
                cnt += 3
            else:
                cnt += 6
        print(cnt)
    return None


def console(*args):  # the judge will not read these print statement
    # print('\033[36m', *args, '\033[0m', file=sys.stderr)
    return


# for case_num in range(int(input())):
    # read line as a string
    # strr = input()

    # read line as an integer
k = int(input())
    
    # read one line and parse each word as a string
    # lst = input().split()

    # read one line and parse each word as an integer
    # lst = list(map(int,input().split()))

    # read matrix and parse as integers (after reading read nrows)
    # lst = list(map(int,input().split()))
    # nrows = lst[0]  # index containing information, please change
    # grid = []
    # for _ in range(nrows):
    #     grid.append(list(map(int,input().split())))

solve(k)
    
    # Google - case number required
    # print("Case #{}: {}".format(case_num+1, res))

    # Codeforces - no case number required
    # print(res)


Measured memory_bytes: 94800
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;
ll intceil(ll a, ll b) {
	return (a + (b - 1)) / b;
}
int main() {
	ll a[5];
	cin >> N;
	for (int i = 0; i < 5; i++)cin >> a[i];
	ans = intceil(N, a[0]);
	ll prev = (a[0] < N) ? a[0] : N;
	for (int i = 1; i < 5; i++) {
		if (prev > a[i]) {
			prev = a[i];
		}
		ans = max(ans, intceil(N, prev));
	}
	cout << (ans + 4) << endl;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, acos, asin, atan, sqrt, tan, cos, pi
from operator import mul
from functools import reduce
from pprint import pprint
from copy import deepcopy


sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


n, k = LI()
A = LI()
D = defaultdict(list)
for i in range(n):
    D[A[i]] += [i]


nxt_idx = [0] * n
for idx_list in D.values():
    for j in range(len(idx_list)):
        nxt_idx[idx_list[j]] = idx_list[(j + 1) % len(idx_list)]



ret = 0
now = 0
L = []
visited = set()
while now not in visited:
    visited.add(now)
    nxt = nxt_idx[now]
    diff = (nxt - now) % n if nxt != now else n
    now = (nxt + 1) % n
    ret += diff + 1
    L += [[ret - 1, nxt]]


ans = []
if (n * k - 1) < ret:
    ss = set()
    for i in range(n * k):
        a = A[i % n]
        if a in ss:
            while a in ss:
                ss.remove(ans.pop())
        else:
            ans += [a]
            ss.add(a)
    print(*ans)
    exit()


ll = (n * k - 1) % ret
bb = bisect_right(L, [ll, INF]) - 1
cc, last_idx = L[bb]
ss = set()
for i in range(ll - cc):
    a = A[(last_idx + i + 1) % n]
    if a in ss:
        while a in ss:
            ss.remove(ans.pop())
    else:
        ans += [a]
        ss.add(a)



print(*ans)



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

#define REP(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#define REPN(i, m, n) for(int (i)=(int)(m); (i)<(int)(n); (i)++)
#define REP_REV(i, n) for(int (i)=(int)(n)-1; (i)>=0; (i)--)
#define debug(x) cout << #x << ": " << (x) << endl;

using namespace std;

int main() {
//    ifstream in("C:\\Users\\P218024\\Documents\\Cpp Projects\\abc094\\sample.txt");
//    cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;

    int X[n] = {0};
    int X_copy[n] = {0};
    REP(i,n) {
        cin >> X[i];
        X_copy[i] = X[i];
    }

    sort(X, X+n);

    int a = X[n / 2 - 1];
    int b = X[n / 2];
    REP(i, n) {
        cout << ((X_copy[i] < b) ? b : a) << endl;
    }

}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <limits>

long long solve(std::vector<int> a)
{
    const int n = a.size();
    long long ans = std::numeric_limits<long long>::max();
    long long sum = 0;

    for (int i = 0; i < n; i++) {
        sum += a[i];
    }

    long long left_sum = 0;
    for (int i = 0; i < n; i++) {
        left_sum += a[i];
        const long long right_sum = sum - left_sum;
        const long long cost = std::abs(right_sum - left_sum);
        ans = std::min(ans, cost);
    }

    return ans;
}

int main(int argc, char *argv[])
{
    int n;
    std::vector<int> a;
    long long ans;

    std::cin >> n;

    a.resize(n);

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

    ans = solve(a);

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int MOD = 1e9 + 7;

int dp[1001][1001];
ll fact[1001];
ll ifact[1001];
ll ipow[1001][1001];
ll modpow(ll a, ll b)
{
	ll r = 1;
	while(b)
	{
		if(b&1) r=(r*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return r;
}

ll inv(ll a)
{
	return modpow(a,MOD-2);
}

int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}

int add(int a, int b)
{
	int res=a+b;
	while(res>=MOD) res-=MOD;
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	fact[0]=1;
	for(ll i = 1; i <= 1000; i++)
	{
		fact[i] = (fact[i-1]*i)%MOD;
	}
	for(ll i = 0; i <= 1000; i++)
	{
		ifact[i] = inv(fact[i]);
	}
	for(int i = 0; i <= 1000; i++)
	{
		for(int j = 0; j <= 1000; j++)
		{
			ipow[i][j] = modpow(ifact[i],j);
		}
	}
	ll n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	for(int i = a; i <= b; i++)
	{
		dp[0][i] = 1;
	}
	for(int i = 1; i <= n; i++)
	{
		for(int j = a; j <= b; j++)
		{
			//dp[i][j]
			if(j>a) dp[i][j] = dp[i][j-1];
			for(int k = c; k <= d && i - k*j >= 0; k++)
			{
				//use k amounts of j groups
				if(j == a)
				{
					if(i-k*j==0) dp[i][j] = add(dp[i][j], mult(ifact[k],ipow[j][k]));
				}
				else
				{
					dp[i][j] = add(dp[i][j], mult(dp[i-k*j][j-1], mult(ifact[k],ipow[j][k])));
				}
			}
			//cerr<<i<<' '<<j<<' '<<mult(dp[i][j],fact[i])<<'\n';
		}
	}
	ll ans = (dp[n][b]*1LL*fact[n])%MOD;
	cout<<ans<<'\n';
}


Measured memory_bytes: 12032
#include <iostream>
#include <cstdio>
#define MN 1000000
#define mod 998244353

int fac[MN + 5], inv[MN + 5];

int C(int a, int b) {if(b < 0 || a - b < 0) return 0; return 1ll * fac[a] * inv[b] % mod * inv[a - b] % mod;}

int inc(int a, int b) {return (a += b) >= mod ? a - mod : a;}
int dec(int a, int b) {return (a -= b) < 0 ? a + mod : a;}

int Catalan(int x, int y, int b)
{
	int dx = y - b, dy = x + b;
	return dec(C(x + y, x), C(dx + dy, dx));
}

int main()
{
	fac[0] = inv[0] = inv[1] = 1;
	for(int i = 1; i <= MN; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
	for(int i = 2; i <= MN; i++) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
	for(int i = 1; i <= MN; i++) inv[i] = 1ll * inv[i - 1] * inv[i] % mod;
	int n, k; scanf("%d%d", &k, &n);
	int b = 0, ans = 0;
	for(int i = std::max(k, (n + 1) / 2); i <= n; i++)
	{
		int j = n - i;
		if(i == j) j--;
		while(b <= j && (i - j) + (j - b) >= k) b++;
		ans = inc(ans, Catalan(i, j, b));
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define endl "\n"
#define ii pair<int, int>
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define make_pair mp
#define MAX (int)1e5+5
#define INF (int)1e9
#define K 26






int32_t main (){
		int n,m;
		cin >> n >> m;
		int c1 = n *(n-1);
		int c2 = m * (m-1);
		c1 = c1/2;
		c2 = c2/2;
		cout << c1 + c2 << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

C = np.array(list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(3)])))

ok = len(set(C[0] - C[1])) == len(set(C[1] - C[2])) == len(set(C[:, 0] - C[:, 1])) == len(set(C[:, 1] - C[:, 2])) == 1
if ok:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 13676
#include <stdio.h>

int main(){
  int k,s,x,y,z,count;
  scanf("%d%d",&k,&s);
  for(x=0;x<=k;x++){
    for(y=0;y<=k;y++){
      int z=s-x-y;
      if(0<=z&&z<=k){
        count++;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 128
X = int(input())

flag = False
for i in range(-10 ** 3, 10 ** 3):
  for j in range(-10 ** 3, 10 ** 3):
    if pow(i, 5) - pow(j, 5) == X:
      print(i, j)
      flag = True
      break
  if flag:
    break


  

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

int main(){
    long long W, H, x, y;
    cin >> W >> H >> x >> y;
    double area = W * H;

    int ways = 0;
    if (W % 2 == 0 and x == W / 2){
        if (H % 2 == 0 and y == H / 2){
            ways = 1;
        }
    }

    cout << area / 2 << " " << ways << endl;
    return 0;
}

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

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 998244353

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    string s;
    cin >> s;
    ll n = s.size();
    ll c = 0, t = 0, j;
    REP(i, 0, n-1) {
        if (s[i] == 'A') {
            t++;
            if (t == 1)
                j = i;
        }
        if (s[i] == 'B' && s[i+1] == 'C') {
            c += t;
            if (t) {
                swap(s[i], s[j]);
                swap(s[i+1], s[j+1]);
            }
            i++;
            continue;
        }
        if (s[i] != 'A')
            t = 0;
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

int main()
{
    long N;
    std::vector<long> L;
    std::cin >> N;
    for(long i=0; i<N; i++){
        long temp;
        std::cin >> temp;
        L.push_back(temp);
    }
    std::sort(L.begin(),L.end());
    long count=0;
    for(long i=0; i<N-2; i++){
        for(long j=i+1; j<N-1; j++){
            for(long k=j+1; k<N; k++){
                if(L[k]<L[i]+L[j]){
                    count++;
                }else{
                    break;
                }
            }
        }
    }
    std::cout << count << std::endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
times=0

while True:
        i=0
        mins=9999999999
        f=False
        start=0
        while i<n:
                if l[i]>0:
                        if f==False:
                                f=True
                                start=i
                        mins=min(mins,l[i])
                elif f:
                        times+=mins
                        j=start
                        while j<i:
                                l[j]-=mins
                                j+=1
                        break
                i+=1
        if i>=n and f==True:
                times+=mins
                j=start
                while j<n:
                        l[j]-=mins
                        j+=1
                
        if f==False:
                break
print(times)

Measured memory_bytes: 39024
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = -1;
        for (int i = 1; i <= n; i++) {
            int a =(int)(i * 1.08);
            if(a == n){
                ans = i;
            }
        }
        System.out.println(ans < 0 ? ":(" : ans);
        sc.close();

    }

}


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

constexpr int N = 1009;
int n, a[N][N];
vector<vector<int>> g(N * N);
vector<int> vis(N * N), mx(N * N);

inline int idx(int i, int j) {
    if(i > j) swap(i, j);
    return i * n + j;
}

void dfs(int u) {
    vis[u] = 1;
    mx[u] = 1;
    for(int v : g[u]) {
        if(vis[v] == 1) {
            cout << -1 << '\n';
            exit(0);
        } else if(vis[v] == 0) dfs(v);
        mx[u] = max(mx[u], 1 + mx[v]);
    }
    vis[u] = 2;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n - 1; ++j) {
            cin >> a[i][j];
            if(j > 1) {
                g[idx(i, a[i][j - 1])].push_back(idx(i, a[i][j]));
            }
        }
    }
    for(int i = 1; i < N * N; ++i) {
        if(vis[i] == 0) dfs(i);
    }
    cout << *max_element(mx.begin(), mx.end()) << '\n';
}


Measured memory_bytes: 53760
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

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

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

	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(b,a*n)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

typedef long long ll;

using namespace std;
using namespace boost::multiprecision;

ll gcd(ll a, ll b){
    if(a < b) return gcd(b, a);

    if(a % b == 0){
        return b;
    }else{
        return gcd(b, a % b);
    }
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

int main(){

    int n,m;
    cin >> n >> m;
    
    vector<ll> a;

    ll lcmi = 1;
    bool b = true;

    rep(i,n){
        int tmp;
        cin >> tmp;

        assert(tmp % 2 == 0);
        a.pback(tmp / 2);
    }

    rep(i,n){

        lcmi = lcm(lcmi, a[i]);

        if(lcmi > (ll)m){
            b = false;
            break;
        }
    }

    rep(i,n){
        
        if((lcmi / a[i]) % 2 == 0){
            b = false;
            break;
        }
    }

    int ans = 0;
    
    if(b){

        for(int i = lcmi; i <= m; i = i + lcmi * 2){
            ans++;
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1528
def solve trans,m,n
  prev = Array.new(n,1.0)
  cur = Array.new(n)
  (m-1).times do
    cur.fill(0)
    n.times do |i|
      n.times do |j|
        cur[i] = [cur[i], prev[j]*trans[j][i]].max
      end
    end
    cur,prev = prev,cur
  end
  prev.max
end

loop do
  n,m = gets.chomp.split.map{|i|i.to_i}
  break if n==0
  trans = []
  n.times do
    trans << gets.chomp.split.map{|i|i.to_f}
  end
  puts "%.2f" % solve(trans,m,n)
end

Measured memory_bytes: 6176
/*
 * Shubham Jain
 */
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 10000000009

int main() {
    FAST_IO
    ll n,i,j,c=0;
    cin>>n;
    ll a[n],count[105]={0};
    for(i=0;i<n;i++){
        cin>>a[i];
        count[a[i]]++;
    }
    for(i=0;i<105;i++){
        if(count[i]>0)
            c++;
    }
    cout<<c<<endl;
return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N; cin >> N;
	repp(i,0,N){
		if(N < 4*i) break;
		if((N-4*i)%7==0) return cout << "Yes" << endl , 0;
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int main(){
    int N;
    cin >> N;
    double ans = 0;
    for(int i = 0; i < N; i++){
        double x;
        string u;
        cin >> x >> u;
        if(u == "JPY"){
            ans += x;
        }else{
            ans += x * 380000;
        }
    }
    fcout << ans << endl;
}


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

using namespace std;

int main(){
  string a,b;
  cin>>a>>b;
  string ans = "";
  if(a.size()>b.size()) ans = "GREATER";
  else if(a.size()<b.size())  ans ="LESS";
else{
	for(int i = 0 ; i<a.size(); i++){
  if(a[i]>b[i]){
	  
	   ans = "GREATER";
	   break;
	   }
  else if(a[i]<b[i]){
  
  ans = "LESS";
  break;
  }
  
  
	}
	
}
if(ans.empty()) ans = "EQUAL";
	cout<<ans;
return 0;
}


Measured memory_bytes: 256
import sys

class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = self.right = None

root = None

def insert(key):
    global root
    x, y = root, None
    while x != None: x, y = x.left if key < x.key else x.right, x
    if y == None: root = Node(key)
    elif key < y.key: y.left = Node(key)
    else: y.right = Node(key)

def find(target):
    result = root
    while result and target != result.key:
        result = result.left if target < result.key else result.right
    return result != None

def inorder(node):
    return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
def preorder(node):
    return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''

input()
for e in sys.stdin:
    if e[0] == 'i': insert(int(e[7:]))
    elif e[0] == 'f': print(['no','yes'][find(int(e[5:]))])
    else: print(inorder(root)); print(preorder(root))


Measured memory_bytes: 55688
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());

        if (n == 1) {
            System.out.println("Hello World");

        } else {
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            System.out.println(a + b);
        }
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <time.h>
int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    printf("%d",6-a-b);
    return 0;
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define mp make_pair
using namespace std;
const int MX = 1007;
const int LIM = 2e5+3;
const int MLOG = 25;
int arr[LIM+3];
int main(){
    int n,k;cin >> n >> k;
    for(int i = k-n+1;i<k+n;i++)
        cout << i << " ";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,j,n) for((i)=(j) ; (i)<(n) ; (i)++)
#define pl(format,var) p(format "\n",var)
#define p(format,var) printf(format,var)
#define asizeof(array) (sizeof(array)/sizeof(array[0]))

#define B_IN_A 2
#define A_IN_B -2
#define CROSSED 1
#define UNTOUCH 0

/*
履歴
・円周が円周上にあるのを、入っているとはみなさないようにした
・デバッグのprintf出したままやったｗ → WA
・円周が円周上にあるのを、入っているみなすようにした → WA
・中心点間の距離の求め方がしくってた → WA
・円周が円周上にあるのを、入っているとはみなさないようにした → WA
・投下 → WA

[メモ1]
A の円周と B の円周が交わっている場合
→これってAとBがただ一点で交わっているケースも含む？
  でも、含まないと出力値が未定義になるから、正しいはず…

d + rb <= ra
→これは B in A とみなしていいの？
  交わっているけど、中に入ってるよ。
  ⇒円周が中に入ってない、と考えれば、正しくないことになる。
    この場合は交わっているとみなそうか。

[メモ2]
言葉の解釈を疑う前に、コード見直そう。

ああ、中心点間の距離も求め方が違うやん。
sqrtとしてないし、y方向の距離も求まってない。
→俺はxaはAの中心点のx座標である、みたいな変換を「脳内で」行うのが苦手みたいだ。
  ワーキングメモリカスすぎるだろ。
  コメントまみれにしないとダメなんかな…まあもう少し様子みるか。

[メモ3]
まだミスってる。どういうこっちゃ。
言葉の解釈の問題がある。
d + rb < ra → d + rb <= ra に戻してみよか。

[メモ4]
hmm...
あーーーーーデバッグのprintf出したままやｗ

[メモ5]
違うなら、言葉の解釈を変える。
d + rb <= ra → d + rb < ra に。

*/
int main(){
	char line[128]; //入力行
	double xa,xb,ya,yb,ra,rb; //入力された円情報
	double d; //中心点間の距離
	int n; //入力データ数
	int i; //カウンタ変数
	
	//入力データ数を取得
	fgets(line, sizeof(line), stdin);
	sscanf(line, "%d", &n);
	
	//各データを処理
	rep2(i,n){
		fgets(line, sizeof(line), stdin);
		sscanf(line, "%lf %lf %lf %lf %lf %lf", &xa, &ya, &ra, &xb, &yb, &rb);
		
		//中心点間の距離と半径から判断
		d = sqrt((xa-xb)*(xa-xb) + (ya-yb)*(ya-yb));
		if(ra + rb < d){
			pl("%d",UNTOUCH);
		}else if(ra + rb == d){
			pl("%d",CROSSED);
		}else if(d + rb < ra){
			pl("%d",B_IN_A);
		}else if(d + ra < rb){
			pl("%d",A_IN_B);
		}else{
			pl("%d",CROSSED);
		}
	}
  return 0;
}

Measured memory_bytes: 652
import math

a, b, x = map(int, input().split())

v = a * a * b
u = v - x

if x >= v / 2:
	print(math.degrees(math.atan((2 * u) / a ** 3)))
elif x < v / 2:
	print(math.degrees(math.atan((a * b * b) / (2 * x))))

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

int main() {
    int n,ans,m;
    cin >> n;
    while (n > 0) {
        ans = 0; 
        m = 2;
        while (1) {
            if (m % 2 == 0) {
                if (n / m < m / 2)break;
                if (n%m == m / 2)ans++;
            }
            else {
                if (n / m < m / 2 + 1)break;
                if (n%m == 0)ans++;
            }
            m++;
        }
        cout << ans << endl;
        cin >> n;
    }
    return 0;
}

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

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

const int MAXN = 3000;

int n;
double arr[MAXN+10];

double dp[MAXN+10][MAXN+10], ans;

int main()
{
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);
    int i, j;

    scanf("%d", &n);
    for(i=1; i<=n; i++) scanf("%lf", &arr[i]);

    dp[0][0]=1;
    for(i=1; i<=n; i++) for(j=0; j<=i; j++)
    {
        dp[i][j]=dp[i-1][j-1]*arr[i]+dp[i-1][j]*(1-arr[i]);
    }

    for(i=n/2+1; i<=n; i++) ans+=dp[n][i];
    printf("%.10f", ans);
    return 0;
}


Measured memory_bytes: 69120
N, M = map(int, input().split())
a = list(int(input()) for i in range(M))
DP = [0]*(N+1)
pointer = 0
for i in range(N+1):
    if pointer < M:
        if i == a[pointer]:
          DP[i] = 0
          pointer += 1
          continue
    if i == 0 or i == 1:
        DP[i] = 1
    else:
        DP[i] = (DP[i-1]+DP[i-2])
print(DP[-1]%1000000007)

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<int64_t> a(3 * n);
    for (auto&& aa : a) {
        cin >> aa;
    }

    vector<int64_t> l(n + 1), r(n + 1);

    priority_queue<int64_t> q;
    int64_t s = 0;
    for (auto i : irange(0L, n)) {
        s += a[i];
        q.push(-a[i]);
    }

    l[0] = s;
    for (auto i : irange(n, 2 * n)) {
        if (a[i] > -q.top()) {
            s -= -q.top();
            s += a[i];
            q.pop();
            q.push(-a[i]);
        }

        l[i - n + 1] = s;
    }

    q = priority_queue<int64_t>();
    s = 0;
    for (auto i : irange(2 * n, 3 * n) | reversed) {
        s += a[i];
        q.push(a[i]);
    }

    r[n] = s;
    for (auto i : irange(n, 2 * n) | reversed) {
        if (a[i] < q.top()) {
            s -= q.top();
            s += a[i];
            q.pop();
            q.push(a[i]);
        }

        r[i - n] = s;
    }

    int64_t ans = numeric_limits<int64_t>::min();
    for (auto i : irange(0L, n + 1)) {
        ans = max(ans, l[i] - r[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 5992
import sys
readline = sys.stdin.buffer.readline
r1,c1,r2,c2 = map(int,readline().split())
mod = 10**9+7
def pow(n,p,mod=10**9+7): #繰り返し二乗法(nのp乗)
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod
def factrial_memo(n=3*10**6+1,mod=10**9+7):
    fact = [1, 1]
    for i in range(2, n + 1):
        fact.append((fact[-1] * i) % mod)
    return fact
def fermat_cmb(n, r, mod=10**9+7): #needs pow,factrial_memo(only fact). return nCk
    return fact[n] * pow(fact[r],mod-2) * pow(fact[n-r],mod-2) %mod
fact = factrial_memo()
r1,c1,r2,c2 = r1+1,c1+1,r2+1,c2+1
al = fermat_cmb(r2+c2,r2)
sub_r = fermat_cmb(r1-1+c2,r1-1)
sub_c = fermat_cmb(r2+c1-1,c1-1)
add_rc = fermat_cmb(r1-1+c1-1,r1-1)

al -= sub_r+sub_c
al += add_rc

print(al%mod)

Measured memory_bytes: 125728
#include<bits/stdc++.h>
using namespace std;
pair<int,int> pii;
vector<int> vec;
int main()
{
  int n,m,p;
  int ac=0,wa=0;
  string s;
  int fl[2][100005]={};
  cin>>n>>m;

  for(int i=0; i<m; i++){
    cin>>p>>s;
    
    if(s=="AC"){
      fl[0][p]=1;
    }else{
      if(fl[0][p]!=1){
	fl[1][p]++;
      }
    }
  }

  for(int i=1; i<=n; i++){
    if(fl[0][i]){
      ac++;
      if(fl[1][i])wa+=fl[1][i];
    }
  }
  cout<<ac<<' '<<wa<<'\n';

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>
using namespace std;
typedef long long ll ;
typedef double db;
typedef long double ldb;
typedef unsigned long long ull ;
//const double PI = acos(-1) ;
db PI=3.1415926;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define for0(i,n)          for(int i=0;i<n;i++)
#define for1(i,n)          for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
//#define gcd(a, b)     __gcd(a, b)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
//#define abs(x)		fabs(x)
#define pcase(z,x)     pf("Case %d: %lld\n",z,x)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)


using namespace std;
ll n,m,y,x,h,e,l,o,z;
//int p,n,arr[2100000],ans;


int main(void)
{
	CIN;
	char p;
	cin>>p;
	if(p=='A')pf("T\n");
	else if(p=='T')pf("A\n");
	else if (p=='G')pf("C\n");
	else pf("G\n");
	
	

}

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

int main(){
  int H,N,sum=0;
  cin>>H>>N;
  for(int i=0;i<N;i++){
    int A;
    cin>>A;
    if(sum+A>=H){
      cout<<"Yes"<<endl;
      return 0;
    }
    sum+=A;
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
def get_divisors(n):
    res = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            res.append(i)
            if i != n // i:
                res.append(n//i)
    return sorted(res)
    
N = int(input())
ds = get_divisors(N)

res = 10**12

if len(ds) % 2 != 0:
    # 平方数の場合
    for i in range((len(ds)+1) // 2):
        res = min(res, ds[i] + ds[-(i+1)])
else:
    # 平方数でない場合
    for i in range(len(ds) // 2):
        res = min(res , ds[i] + ds[-(i+1)])
        
print(res - 2)

Measured memory_bytes: 3280
def BinarySearch(L, key, mode):
    left, right = 0, len(L)
    mid = len(L)//2
    while  left <= right-1:
        if L[mid] < key and mode == 0 or L[mid] <= key and mode == 1:
            left = mid+1
        else:
            right = mid
        mid =  (left+right)//2
    return right

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

A.sort()
C.sort()
ans = 0
for i in B:
    Ai = BinarySearch(A, i, 0)
    Ci = len(C)-BinarySearch(C, i, 1)
    ans += Ai*Ci
print(ans)

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


int main(){
    char a[50][50];
    int h,w,f=0;
    cin>>h>>w;
    rep(i,h){
        rep(j,w){
            cin>>a[i][j];
        }
    }
    rep(i,h){
        rep(j,w){
            if(a[i][j]=='#' && a[i+1][j]=='.' && a[i-1][j]=='.' && a[i][j+1]=='.' && a[i][j-1]=='.'){
                f++;
            }
        }
    }
    if(f==0) cout<<"Yes" << endl;
    else cout<<"No" << endl;
    
    
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[100005],k,x=1e9+7,y,sum; 
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]<x) x=a[i],y=i;
	} 
    sum=n-1;
	sum=(sum+k-2)/(k-1);
	cout<<sum;
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n;
    cin>>n;
    VL a(n);
    REP(i,n)cin>>a[i];
    bool yes = true;
    REP(i,n){
        if(a[i] % 2 == 0){
            if(!(a[i] % 3 == 0 || a[i] % 5 == 0)){
                yes = false;
                break;
            }
        }
    }
    PUTS(yes? "APPROVED" : "DENIED");
}

Measured memory_bytes: 256