akhauriyash/Code-Regression huggingface dataset:
n, q = map(int, input().split())
s = input()
dic = {}
t_list = []
d_list = []

for i in range(q):
    t, d = input().split()
    t_list.append(t)
    if d == 'L':
        d_list.append(-1)
    else:
        d_list.append(1)


def find_pos(left, right):
    return left + (right - left - 1) // 2


def calc(sites, ts, ds):
    def check(idx):
        num = idx
        for j in range(q):
            site = sites[num]
            if ts[j] == site:
                num += ds[j]
            if num < 0:
                return -1
            if num > n - 1:
                return 1
        return 0

    def func(left, right):
        assert left > -1
        assert right < n + 1
        if right - left == 1:
            if check(left) > -1:
                return left
            else:
                return right
        pos = find_pos(left, right)
        if check(pos) > -1:
            return func(left, pos + 1)
        else:
            return func(pos + 1, right)
    return func


f1 = calc(s, t_list, d_list)
f2 = calc(s[::-1], t_list, [-i*1 for i in d_list])
print(n - f1(0, n) - f2(0, n))

Measured memory_bytes: 8560
nm=input().split(" ")
N=int(nm[0])
M=int(nm[1])
log=[0]*N
wacount=0
account=0
for i in range(M):
  ps=input().split(" ")
  p=int(ps[0])-1
  s=True if ps[1]=="AC" else False
  if log[p]!=-1:
    if s:
      account+=1
      wacount+=log[p]
      log[p]=-1
    else:
      log[p]+=1
print(str(account)+" "+str(wacount))

Measured memory_bytes: 3828
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>

using namespace std;

#line 2 "abc161_a.cpp"

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


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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

const long long MOD = 998244353;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N, std::vector<ll> D) {
  vector<ll> m(N, 0);
  ll mx = 0;
  rep(i, N) {
    m.at(D.at(i))++;
    chmax(mx, D.at(i));
  }

  if (m.at(0) != 1 || D.at(0) != 0) {
    cout << 0 << endl;
    return;
  }

  ll answer = 1;

  FOR(i, 1, mx + 1) {
    if (m.at(i) == 0) {
      answer = 0;
      break;
    }
    rep(j, m.at(i)) {
      answer *= m.at(i - 1);
      answer %= MOD;
    }
  }

  cout << answer << endl;
}

int main() {
  ll N;
  scanf("%lld", &N);
  std::vector<ll> D(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &D[i]);
  }
  solve(N, std::move(D));
  return 0;
}


Measured memory_bytes: 4868
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

import itertools

li = [i for i in range(1,n+1)]
li2 = list(itertools.permutations(li))

cnt = 0
for i in li2:
    cnt +=1
    if i == p:
        a = cnt
    if i == q:
        b = cnt

print(abs(a-b))

Measured memory_bytes: 13900
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
void solve()
{
    int n;
    cin >> n;
    int ac=0, re=0, tle=0, wa=0;
    while(n--){
        string s;

        cin>>s;
        if(s[0]=='A'){
            ac++;
        }
        if(s[0]=='W'){
            wa++;
        }
        if(s[0]=='R'){
            re++;
        }
        if(s[0]=='T'){
            tle++;
        }
    }
    cout << "AC x " << ac << endl
         << "WA x " << wa << endl
         << "TLE x " << tle << endl
         << "RE x " << re << endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1;
    //cin >> tc;
    while (tc--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>

int main(){
	int n,i;
	scanf("%d",&n);
	int a[n],b[n],c[n];
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);}
	for(i=0;i<n;i++){
		if(a[i]*a[i]+b[i]*b[i]==c[i]*c[i]||a[i]*a[i]+c[i]*c[i]==b[i]*b[i]||a[i]*a[i]==b[i]*b[i]+c[i]*c[i])printf("YES\n");
		else printf("NO\n");}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

void solve() {
    int r;
    cin>>r;
    cout<<2 * PI * r<<endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int t = 1;
    //cin>>t;
    for(int test = 1; test <= t; test++) {
        //cout<<"Case #"<<test<<": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 3804
//123B
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
int main(void){
    vector<tuple<int, int>>L;
    string t_s=" ";
    int t_back =0, t=0;
    int ans =0, extra=0;
    rep(i, 5){
        cin >> t_s;
        t_back = t_s.back()-'0';  //文字列→数値
        t =stoi(t_s); //文字列→数値
        if (t_back==0){
            ans+=t;
            L.push_back(make_tuple(t_back, t));
        }else{
            ans +=t+10-t_back;
            L.push_back(make_tuple(t_back, t));
        }
    }
    sort(L.begin(), L.end());
    rep(i, 5){
        if(get<0>(L[i]) != 0){
            extra = 10- get<0>(L[i]);
            break;
        }
    }
    cout << ans-extra;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
pair<int,int> dat[10];
char p[10][21];
int main(){
	int a;
	bool saisho=true;
	while(scanf("%d",&a),a){
		if(!saisho)printf("\n");
		saisho=false;
		for(int i=0;i<a;i++){
			int b,c,d;
			scanf("%s%d%d%d",p[i],&b,&c,&d);
			dat[i]=make_pair(-(b*3+d),i);
		}
		std::sort(dat,dat+a);
		for(int i=0;i<a;i++){
			printf("%s,%d\n",p[dat[i].second],-dat[i].first);
		}
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;

int main(){
    double tmp,diff=1000000;
    int ans,i,N,T,A;
    cin>>N>>T>>A;
    vector<double> H(N);
    for(i=0;i<N;i++){
        cin>>H[i];
        tmp = abs(A - (T - H[i] * 0.006));
        if(diff>tmp){
            ans = i;
            diff = tmp;
        }
    }
    cout<<ans+1<<endl;
    return 0;
}

Measured memory_bytes: 256
$S = gets.chomp
$res = 0

def calc(order, plus_flag)
  $memo << order if plus_flag == 1
  if order == $S.size - 1 then
    if $memo.size == 1 then
      $res += $S.to_i
    else
      ($memo.size).times do |i|
        if i != $memo.size-1
          $res += $S[$memo[i], $memo[i+1]-$memo[i]].to_i
        else
          $res += $S[$memo[i], $S.size-$memo[i]].to_i
        end
      end
    end
  else
    calc(order + 1, 1)
    calc(order + 1, 0)
  end
  $memo.pop if plus_flag == 1
end

if $S.size == 1
  puts $S.to_i
else
  $memo = []
  $memo << 0
  calc(1, 1)
  $memo.clear
  $memo << 0
  calc(1, 0)

  puts $res
end


Measured memory_bytes: 14332
#include<stdio.h>

int main(void)
{
	int total,book_price;
	int i;

	while (1) {
		scanf("%d", &total);
		if (total == 0)break;
		for (i = 0; i < 9; i++) {
			scanf("%d", &book_price);
			total -= book_price;
		}
		printf("%d\n", total);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <cmath>


int main()
{
    long long N, A, B, C, D, E;
    std::cin >> N >> A >> B >> C >> D >> E;
    long long min = std::min({ A,B,C,D,E });
    long long ans = 4 + (N + min - 1) / min;
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

fun main(args: Array<String>){
    val scanner = Scanner(System.`in`)
    val sa = scanner.next()
    val sb = scanner.next()
    val a = Integer.parseInt(sa)
    val b = Integer.parseInt(sb)
    var i = 0
    if (a >= b){
        for (i in 0..a-1){
            print(b)
        }
    } else {
        for (i in 0..b-1){
            print(a)
        }
    }
}

Measured memory_bytes: 31272
s = []
for i in range(4):
    s.append(int(input()))

count = 0
for a in range(s[0] + 1):
    for b in range(s[1] + 1):
        for c in range(s[2] + 1):
            if( a*500 + b*100 + c*50 == s[3] ):
                count = count + 1

print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int l[210];

bool x(int a,int b)
{
	return a<b;
}

int main()
{
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=2*n;i++) cin>>l[i];
	sort(l+1,l+2*n+1,x);
	for(int i=1;i<=2*n;i+=2) ans+=l[i];
	cout<<ans<<endl;
	return 0;
}

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


void solve(){
    int n; cin >> n;
    vector<int> A;
    for(int i = 0; i < n; i++){
        int k; cin >> k;
        A.push_back(k);
    }
    int best_ans = 1e9;
    for(int i = -100; i <= 100; i++){
        int curr = 0;
        for(int j : A){
            curr += (j-i)*(j-i);
        }
        best_ans = min(curr, best_ans);
    }
    cout << best_ans << "\n";
}

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

    bool multitest = false;
//    multitest = true;
    if(multitest){
        int t; cin >> t;
        while(t--)
            solve();
    }
    else
        solve();
}






Measured memory_bytes: 3652
import sys
import os
from operator import itemgetter

N,M = map(int,input().split())
cities = [ 0 for _ in range(M) ]

for i in range(M):
    p,y = map(int,input().split())
    cities[i] = [p,y,i]
cities = sorted(cities,key=itemgetter(1))
cities = sorted(cities,key=itemgetter(0))

out = ["*" for _ in range(M)]
beforeCity = cities[0][0]
cityCnt = 1
for i in range(M):
    curCity = cities[i][0]
    if beforeCity != curCity:
        cityCnt = 1
    cityNo1 = str(curCity).zfill(6)
    cityNo2 = str(cityCnt).zfill(6)
    out[cities[i][2]] = cityNo1+cityNo2
    beforeCity = curCity
    cityCnt += 1

for a in out:
    print(a)


Measured memory_bytes: 31320
#include <stdio.h>

int main(void) {
	int W, H, N;
	int i;
	int l, r, d, u;
	if (scanf("%d%d%d", &W, &H, &N) != 3) return 1;
	l = 0; r = W; d = 0; u = H;
	for (i = 0; i < N; i++) {
		int x, y, a;
		if (scanf("%d%d%d", &x, &y, &a) != 3) return 1;
		switch (a) {
			case 1: if (l < x) l = x; break;
			case 2: if (x < r) r = x; break;
			case 3: if (d < y) d = y; break;
			case 4: if (y < u) u = y; break;
		}
	}
	printf("%d\n", r < l || u < d ? 0 : (r - l) * (u - d));
	return 0;
}


Measured memory_bytes: 128
//region #include <cp_helper>
#include <vector>
#include <iostream>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define vll vector<ll>
#define vii vector<pair<int, int>>
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define viin(a, n) for (ll i=0; i<n; ++i) in2(arr[i].first, arr[i].second)
#define out(n) cout << n
#define outn(n) out(n) << '\n'
#define fori(i, n) for (ll i=0; i<n; ++i)
#define ford(i, n) for (ll i=n-1; i>=0; --i)
const int mod = (int)(1e9) + 7;
//endregion

ll num_groups, p[100005], grpsize[100005];
int par(int x) { return (p[x]==x)? x:par(p[x]); } //No compression
bool isSameGroup(int a, int b) { return par(a) == par(b); }
void merge(int a, int b) {
    a = par(a), b = par(b);
    num_groups -= (!isSameGroup(a, b));
    if (grpsize[a] < grpsize[b]) {
        p[a] = b;
        grpsize[b] += grpsize[a];
    }
    else {
        p[b] = a;
        grpsize[a] += grpsize[b];
    }
}

int main() {
    io();
    ll n, m, t, x, y;
    in2(n, m);
    vll ans(m);
    fori (i, n) p[i] = i, grpsize[i] = 1;
    num_groups = n;
    vii arr(m);
    viin(arr, m);
    t = n*(n-1)/2;
    ford (i, m) {
        ans[i] = t;
        x = par(arr[i].first-1), y = par(arr[i].second-1);
        if (x == y) continue;
        t -= (grpsize[x] * grpsize[y]);
        merge(x, y);
    }
    fori (i, m) outn(ans[i]);
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // maximise value given capacity
    ll n,cap;
    cin>>n>>cap;
    ll val[n+10],w[n+10];
    ll dp[cap+1][n+1]={0};
    for(ll i=1;i<=n;i++){
        cin>>w[i]>>val[i];
    }
    for(ll i=0;i<=cap;i++){
        for(ll j=0;j<=n;j++){
            if(i==0 || j==0){dp[i][j]=0;continue;}
            dp[i][j] = dp[i][j-1];
            if(w[j]<=i){dp[i][j] = max(dp[i][j],dp[i-w[j]][j-1] + val[j]);}
        }
    }
    cout<<dp[cap][n];cout<<"\n";
    // for(ll i=1;i<=n;i++)cout<<w[i]<<" ";cout<<"\n";
    // for(ll i=1;i<=n;i++)cout<<val[i]<<" ";cout<<"\n";
    // for(ll i=0;i<=cap;i++){
    //     for(ll j=0;j<=n;j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }

    return 0;
}    

Measured memory_bytes: 79232
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
template<typename T> T ctmax(T &x, const T &y){ return x = max(x, y); }
template<typename T> T ctmin(T &x, const T &y){ return x = min(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

vector<long long> monotone_queue_dp(int n, long long init, auto cost){
	vector<long long> dp(n, init);
	auto cross = [&](int i, int j){
		int l = j, r = n;
		while(r - l > 1){
			int mid = l + r >> 1;
			dp[i] + cost(i, mid) <= dp[j] + cost(j, mid) ? l = mid : r = mid;
		}
		return l;
	};
	deque<int> q{0};
	for(auto i = 1; i < n; ++ i){
		while(int(q.size()) > 1 && cross(*q.begin(), *next(q.begin())) < i) q.pop_front();
		dp[i] = dp[q.front()] + cost(q.front(), i);
		while(int(q.size()) > 1 && cross(*next(q.rbegin()), *q.rbegin()) >= cross(*q.rbegin(), i)) q.pop_back();
		q.push_back(i);
	}
	return dp;
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n;
	long long c;
	cin >> n >> c;
	vector<int> h(n);
	for(auto i = 0; i < n; ++ i){
		cin >> h[i];
	}
	cout << monotone_queue_dp(n, 0, [&](int i, int j){ return 1LL * 1LL * (h[i] - h[j]) * (h[i] - h[j]) + c; }).back();
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n,k,x,y;
  cin>>n>>k>>x>>y;
  if(n<=k) cout<<x*n<<'\n';
  else cout<<x*k+y*(n-k)<<'\n';
  return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int N ;
  cin >> N ;
  string ans = "APPROVED";
  
  rep(i,N){
    int c ;
    cin >> c ;
    if( c%2 == 0){
      if( (c%5 !=0) && (c%3 != 0))
        ans = "DENIED";
      }
  }
    
  cout << ans ; 

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>

#include <vector>
#include <algorithm>

class BC{
 public:
  int B;
  int C;
  BC(const int B_, const int C_){
    B = B_;
    C = C_;
  }
};

int main(){
  int N,M;
  scanf("%d%d",&N,&M);
  int A[N];
  for(int i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  std::vector<BC> bc;
  for(int i=0;i<M;i++){
    int B,C;
    scanf("%d %d",&B,&C);
    bc.push_back(BC(B,C));
  }
  std::sort(A,A+N);
  std::sort(bc.begin(),
	    bc.end(),
	    [](const BC& a,const BC& b){return a.C > b.C;}
	    );

  long count = 0;
  for(int i=0;i<M;i++){
    for(int j=0;j<bc[i].B;j++){
      if(A[count] < bc[i].C && count!=N){
	A[count] = bc[i].C;
	count++;
      }else{
	break;
      }
    }
  }
  unsigned long long sum = 0;
  for(int i=0;i<N;i++){
    sum += A[i];
  }
  printf("%llu\n",sum);
}


Measured memory_bytes: 1784
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;


int main(){
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  vector<int> A({a1, a2, a3});
  sort(A.begin(), A.end());
  
  cout << (A[1] - A[0]) + (A[2] - A[1]) << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define inc(a) scanf("%c", &(a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//      puts(a) printf("%s\n", a) 文字はこっち
//your code here!
int main(void){
    ll alph[26]={0};
    char S[100100];
    ins(S);
    //ll idx=0;
    //while(S[idx]!='\0') alph[S[idx++]-'a']++;
    ll N=strlen(S);
    rep(i, N) alph[S[i]-'a']++;
    rep(i, 26){
        if(!alph[i]){
            putchar('a'+i);
            return 0;
        }
    }
    puts("None");
    return 0;
}


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

int main(){
  string a;
  string c;
  cin>>a;

  for(int bit=0;bit<(1<<3);++bit){
    int sum=a[0]-'0';
    for(int t=0;t<3;++t){
      if(bit&(1<<t)){
        int temp =a[t+1]-'0';
        sum+=temp;
        c[t]='+';
      }else {
        int temp =a[t+1]-'0';
        sum-=temp;
        c[t]='-';
      }
    }
    if(sum==7)break;
  }

  for(int t=0;t<4;t++){
    if(t==3){
      cout<<a[t]<<"=7";
    }else{
      cout<<a[t]<<c[t];
    }
  }

  return 0;
}


Measured memory_bytes: 256
import numpy as np

d = int(input())
c = np.array(list(map(int,input().split())))
s = np.array([[int(i) for i in input().split()] for _ in range(d)])
ld = np.zeros(26)

ans = 0

for i in range(d):
    ld += 1
    mi = np.argmax(s[i])
    ld[mi] = 0
    #ans += s[i][mi]
    #ans -= sum(ld * c)
    print(mi+1)    

Measured memory_bytes: 27408
#include <stdio.h>
void gcd(int x, int y);
void swap(int m, int n);

int main(void)
{
    int a, b = 0;
    scanf("%d %d", &a, &b);
    gcd(a, b);
    return 0;
}
void swap(int m, int n)
{ int z = m; m = n; n = z; }
void gcd(int x, int y)
{
    if(x < y) swap(x, y);
    while(y > 0)
    {
        int r = x % y;
        x = y;
        y = r;
    }
    printf("%d\n", x);
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int dig(int n){
    int keta = 0;
    while(n > 0){
        n /= 10;
        keta++;
    }
    return keta;
}

int main() {
    int n,medup,meddw;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    auto y = x;
    sort(y.begin(),y.end());
    medup = y[n/2],meddw = y[n/2-1];
    for (int i= 0; i < x.size(); ++i) {
        if(x[i] >= medup) cout << meddw << endl;
        else cout << medup << endl;
    }
    return 0;
}


Measured memory_bytes: 3712
package main
import "fmt"

var N int

func main(){
  fmt.Scanf("%d", &N)
  v := make([]int, N+1)
  for i:=1; i<=N; i++ {
    for j:=i; j<=N; j+=i {
    	v[j]++
    } 
  }
  ans := int64(0)
  for i:=1; i<=N; i++ {
    ans += int64(i)*int64(v[i])
  }
  fmt.Println(ans)
}

Measured memory_bytes: 82560
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 

using namespace std;

const int MOD = 1000000007;

int n, m;
int a[100010];
bool isBroken[100010];
int f[100000];	//到第i个台阶有多少步 

int main()
{
	scanf("%d%d", &n, &m);
	
	for (int i = 0 ; i <= n ; i++)
		isBroken[i] = false;

	for (int i = 0 ; i < m ; i++)
	{
		scanf("%d", &(a[i]));
		isBroken[a[i]] = true;
	}

		
	f[0] = 1;
	for (int i = 1 ; i <= n ; i++)
	{
		if (isBroken[i])
		{
			f[i] = 0;
		}
		else
		{
			f[i] = 0;
			if ((i - 1) >= 0)
				f[i] = (f[i] + f[i - 1]) % MOD;
				
			if ((i - 2) >= 0)
				f[i] = (f[i] + f[i - 2]) % MOD;
		}
	}
	
	printf("%d\n", f[n]);

	return 0;
}


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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i=0;i<N;i++) cin >> A.at(i);
  if((N-1)%(K-1)==0) cout << (N-1)/(K-1) << endl;
  else cout << (N-1)/(K-1) + 1 << endl;
}


Measured memory_bytes: 640
N, M = map(int, input().split())

def fac(n, mod):
    a = 1
    for i in range(n, 0, -1):
        a = (a * i) % mod
    return a
    
def solve(N, M):
    mod = 10**9 + 7
    if N > M + 1 or M > N + 1:
        return 0
    if N == M:
        return (2 * fac(N, mod)**2) % mod
    else:
        return (fac(N, mod) * fac(M, mod)) % mod

print(solve(N, M))

Measured memory_bytes: 3060
#include <iostream>
#include <string>

using namespace std;

int main(){

    int N; cin >> N;
    long long m = 1000000001;
    long long ans;
    for (int i = 0; i < N; i++){
        int A, B; cin >> A >> B;

        if (m > B){
            m = B;
            ans = A + B;
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))


struct pos{
	double x,y,z;
	double norm,norm2;
	pos tov(pos a){
		return (a-(*this));
	}
	void initnorm(){
		norm2=x*x+y*y+z*z;
		norm=sqrt(norm2);
	}
	pos operator+(pos a)const{
		pos res=a;
		res.x+=x; res.y+=y; res.z+=z;
		res.initnorm();
		return res;
	}
	pos operator-(pos a)const{
		pos res=(*this);
		res.x-=a.x; res.y-=a.y; res.z-=a.z;
		res.initnorm();
		return res;
	}
	double dot(pos a){
		return x*a.x + y*a.y + z*a.z;
	}
	pos(double ix,double iy,double iz){
		x=ix; y=iy; z=iz;
	}
	pos(){}
	string str(){
		char ns[50];
		sprintf(ns,"(%.1lf %.1lf %.1lf)",x,y,z);
		return	string(ns);
	}
};


struct line{
	pos p,q;
	pos vec;
	string str(){
		return ("("+p.str()+"-"+q.str()+")");
	}
	line(pos ip,pos iq){
		p=ip; q=iq;
		vec=p.tov(q);
	}
	line(){}
	double dist(pos a){
		if(p.tov(a).dot( p.tov(q) )<0)return p.tov(a).norm;
		if(q.tov(a).dot( q.tov(p) )<0)return q.tov(a).norm;
		if(p.tov(a).norm<1e-9)return p.tov(a).norm;
		if(q.tov(a).norm<1e-9)return q.tov(a).norm;
		
		pos pa = p.tov(a);
		double co = abs(acos(max(-1.0,min(1.0,pa.dot(vec)/vec.norm/pa.norm))));
		//printf("%lf\n",pa.dot(vec));
		return pa.norm*sin(co);
	}
};

pos sc[2005];
double sr[2005];

pos tc[20];
double tr[20];
double ds[20];

int isc[25][2005];

int n,m,r;
int main(void){
	for(;;){
		scanf("%d%d%d",&n,&m,&r);
		if(n+m+r==0)break;
		rep(i,n){
			double x,y,z;
			scanf("%lf%lf%lf%lf",&x,&y,&z,&sr[i]);
			sc[i]=pos(x,y,z);
		}
		rep(i,m){
			double x,y,z;
			scanf("%lf%lf%lf%lf",&x,&y,&z,&tr[i]);
			tc[i]=pos(x,y,z);
		}
		pos oc;
		{
			double x,y,z;
			scanf("%lf%lf%lf",&x,&y,&z);
			oc = pos(x,y,z);
		}
		memset(isc,0,sizeof(isc));
		
		rep(i,m){
			line a(oc,tc[i]);
			rep(j,n){
				if(sc[j].tov(oc).norm<sr[j] && sc[j].tov(tc[i]).norm<sr[j])continue;
				if(a.dist(sc[j])>sr[j])continue;
				isc[i][j]=1;
			}
			ds[i] = tr[i]/a.vec.norm2;
		}
		/*
		rep(i,m){
			line a(oc,tc[i]);
			rep(j,n){
				printf("%d %d %s %d %s %lf %lf\n",
					isc[i][j],
					i,a.str().c_str(),
					j,sc[j].str().c_str(),
					a.dist(sc[j]),
					sr[j]);
			}
		}*/
		
		double ans=0;
		
		rep(i,1<<m){
			int cn=0;
			rep(j,n){
				bool b=false;
				rep(k,m){
					if((i&(1<<k))==0)continue;
					if(isc[k][j])b=true;
				}
				if(b)cn++;
			}
			if(cn>r)continue;
			double ns=0;
			rep(j,m){
				if((i&(1<<j))==0)continue;
				ns += ds[j];
			}
			//printf("%d %d %lf\n",i,cn,ns);
			
			ans=max(ans,ns);
		}
		printf("%f\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1620
// Getting Started - Insertion Sort

using System;
using System.Collections.Generic;

class program
{
    public static void Main()
    {
        var str = Console.ReadLine().Split(' ');
        var x = int.Parse(str[0]);
        var y = int.Parse(str[1]);
        Console.WriteLine(gcd(x, y));
    }

    public static int gcd(int x, int y)
    {
        var high = x > y ? x : y;
        var low = high == x ? y : x;
        
        while (true)
        {
            var m = 0;
            while (high - m * low >= 0)
            {
                m++;
            }
            m--;

            if (high - m * low == 0)
            {
                return low;
            }
            else
            {
                var buf = high - low * m;
                high = low;
                low = buf;
            }
        }
    }
}

Measured memory_bytes: 13772
let n = read_int ()
let s = Array.init n (fun _ -> Scanf.scanf "%s\n" (fun s -> s)) 

let rec f i a w t r =
  if i = n then
    Printf.printf "AC x %d\nWA x %d\nTLE x %d\nRE x %d\n" a w t r
  else
    match s.(i).[0] with
      'A' -> f (i + 1) (a + 1) w t r
    | 'W' -> f (i + 1) a (w + 1) t r
    | 'T' -> f (i + 1) a w (t + 1) r
    |  _  -> f (i + 1) a w t (r + 1)

let () = f 0 0 0 0 0


Measured memory_bytes: 8568
#include<bits/stdc++.h>
using namespace std;
int n,a[101],x,y,h;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		h+=a[i];
	}
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x>>y;
		cout<<h-a[x]+y<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<double, double> p;
constexpr double DISTANCE = 1e9;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<p> holes(N);
    double ax = 0.0l, ay = 0.0l;
    for (auto&& h : holes) {
        double x, y;
        cin >> x >> y;
        h = p(x, y);
        ax += x;
        ay += y;
    }

    ax /= holes.size();
    ay /= holes.size();

    for (auto&& h : holes) {
        h = p(h.first - ax, h.second - ay);
    }

    vector<ll> cupin(N, 0);
    ll cnt = 0;
    double delta = M_PI / 1800000.0;
    for (double theta = 0; theta < 2 * M_PI; theta += delta) {
        double maxi = -1e100;
        double idx = -1;
        
        double cosine = cos(theta);
        double sine   = sin(theta);

        for (ll i = 0; i < N; i++) {
            double r = holes[i].first * cosine + holes[i].second * sine;
            if (r > maxi) {
                maxi = r;
                idx = i;
            }
        }

        cupin[idx]++;
        cnt++;
    }

    for (auto c : cupin) {
        printf("%.15f\n", (double)c / (double)cnt);
    }
}



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

int main() {
	
	int A, B, C;
	cin >>A >>B >>C;
	
	if(A>=B+C){
		
		cout <<0 <<endl;
		
	}
	else{
		
		cout <<C-A+B <<endl;
		
	}
	
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define LIMIT 1000000
int main(void){
  int N,i,judge=0;
  long long int A[LIMIT] = {0},mult = 1;
  scanf("%d",&N);
  for(i=0; i<N; i++){
    scanf("%lld",&A[i]);
    if(A[i]==0){
      printf("0\n");
      return 0;
    }
  }

  
  for(i=0; i<N; i++){
    if(A[i]<=1000000000000000000/mult){
      mult *= A[i];
    }else{
      printf("-1\n");
      judge = 1;
      break;
    }
  }
  
  if(judge == 0){
    printf("%lld\n",mult);
  }
  return 0;
}
  
  



    


Measured memory_bytes: 9516
#include<bits/stdc++.h>
#define ll long long
#define re register
#define ull unsigned ll
using namespace std;
inline ll read(){
	ll s=0,t=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*t;
}
const int N=1005;
const int M=40;
char s[M];
int n,Num,len[M];
struct Node{ll x,y;}p[N];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++)p[i]=(Node){read(),read()};
	int t=abs(p[1].x+p[1].y)&1;
	for(int i=1;i<=n;i++)if((abs(p[i].x+p[i].y)&1)^t)return puts("-1"),0;
	printf("%d\n1",32-t),len[Num=1]=1;
	if(t){for(int i=1;i<=30;i++)printf(" %d",len[++Num]=1<<i);}
	else {for(int i=0;i<=30;i++)printf(" %d",len[++Num]=1<<i);}
	puts("");
	for(int i=1;i<=n;i++){
		ll nx=0,ny=0;
		for(int j=Num;j>=1;j--){
			ll dx=p[i].x-nx,dy=p[i].y-ny;
			if(abs(dx)>abs(dy)){
				if(dx>0)s[j]='R',nx+=len[j];
				else s[j]='L',nx-=len[j];
			}
			else{
				if(dy>0)s[j]='U',ny+=len[j];
				else s[j]='D',ny-=len[j];				
			}
		}printf("%s\n",s+1);
	}
	return 0;
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
const int N=3 +5;
#define FOR(i,a) for(int i=0;i<(a);i++)
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	double  a,b,c;
	cin>>a>>b>>c;
	if (abs(a-b) < 1e-9){
		if(abs(a-c) >= 1e-9 || abs(c-b) >= 1e-9){
			cout<<"Yes";
			return 0;
		}
		
	}
	else if (abs(a-c) < 1e-9){
		if(abs(a-b) >= 1e-9 || abs(c-b) >= 1e-9){
			cout<<"Yes";
			return 0;
		}
		
	}
	else if (abs(c-b) < 1e-9){
		if(abs(a-c) >= 1e-9 || abs(a-b) >= 1e-9){
			cout<<"Yes";
			return 0;
		}
		
	}
		cout<<"No";	
	return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b,c,x,y = inpl()
if x>y: tmp = c*y*2+a*(x-y)
else: tmp = c*x*2+b*(y-x)
tmp = min(tmp, c*max(x,y)*2)
print(min(a*x+b*y,tmp))

Measured memory_bytes: 64016
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n,a,b;
  cin>>n>>a>>b;
  a--;b--;
  vector<Int> x(n),y(n);
  set<pair<Int, Int> > sp;
  for(Int i=0;i<n;i++){
    cin>>x[i]>>y[i];
    sp.emplace(x[i]+y[i],x[i]-y[i]);
  }

  Int d=max(abs((x[a]+y[a])-(x[b]+y[b])),abs((x[a]-y[a])-(x[b]-y[b])));
  vector<Int> used(n,0);
  
  {
    map<Int, map<Int, Int> > U,V;
    for(Int i=0;i<n;i++){
      U[x[i]+y[i]][x[i]-y[i]]=i;
      V[x[i]-y[i]][x[i]+y[i]]=i;
    }
    const Int INF = 1e12;
    for(auto &p:U) p.second[INF]=p.second[-INF]=-1;
    for(auto &p:V) p.second[INF]=p.second[-INF]=-1;

    queue<Int> q;
    used[a]=used[b]=1;
    q.emplace(a);
    q.emplace(b);
    while(!q.empty()){
      Int w=q.front();q.pop();
      Int u=x[w]+y[w],v=x[w]-y[w];
      auto check=[&](auto &W,auto &Z,Int s,Int t){
	if(W.count(s)){
	  auto latte=W[s].lower_bound(t-d);
	  while(latte->first<=t+d){
	    used[latte->second]=1;
	    q.emplace(latte->second);
	    Z[latte->first].erase(Z[latte->first].find(s));
	    latte=W[s].erase(latte);
	  }
	}
      };
      check(U,V,u-d,v);
      check(U,V,u+d,v);
      check(V,U,v-d,u);
      check(V,U,v+d,u);
    }
  }

  if(0) for(Int i=0;i<n;i++) cout<<i<<":"<<used[i]<<endl;
  map<Int, vector<Int> > U,V;
  for(Int i=0;i<n;i++){
    U[x[i]+y[i]].emplace_back(x[i]-y[i]);
    V[x[i]-y[i]].emplace_back(x[i]+y[i]);
  }
  
  const Int INF = 1e12;
  auto calc=[&](auto &W){
    for(auto &p:W){
      p.second.emplace_back(INF);
      p.second.emplace_back(-INF);
      sort(p.second.begin(),p.second.end());
    }
  };
  calc(U);
  calc(V);

  Int ans=0;
  for(Int i=0;i<n;i++){
    if(!used[i]) continue;
    auto cnt=[](auto &W,Int s,Int t){
      return upper_bound(W.begin(),W.end(),t)-lower_bound(W.begin(),W.end(),s);
    };
    Int u=x[i]+y[i],v=x[i]-y[i];
    ans+=cnt(U[u+d],v-d,v+d);
    ans+=cnt(U[u-d],v-d,v+d);
    ans+=cnt(V[v+d],u-d,u+d);
    ans+=cnt(V[v-d],u-d,u+d);
    
    if(sp.count(make_pair(u+d,v+d))) ans--;
    if(sp.count(make_pair(u+d,v-d))) ans--;
    if(sp.count(make_pair(u-d,v+d))) ans--;
    if(sp.count(make_pair(u-d,v-d))) ans--;
  }
  
  cout<<ans/2<<endl;
  return 0;
}


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

int main() {
  int a, b, c;
  int count = 0;
  cin >> a >> b >> c;

  for (int x = a; x <= b; x++) {
    if (c % x == 0) {
      count++;
    }
  }
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 1160
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;

	int x = 0;
	int maxx = 0;
	for (auto c : s) {
		if (c == 'I') {
			x++;
			maxx = max(maxx, x);
		}
		else
			x--;
	}
	maxx = max(maxx, x);
	cout << maxx << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
	Scanner stdIn=new Scanner(System.in);
	int[] S = new int[3];
	for(int i=0;i<3;i++){
	    S[i] = stdIn.nextInt();
	}
	Arrays.sort(S);
	int j =S[2]-S[1];
	int k =S[1]-S[0];
	System.out.println(j+k);
    }
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int n;
ll a[1000000];
ll ak[1000000],bk[1000000];
ll ans=LLONG_MIN;

int main(){
  cin>>n;
  rep(i,3*n){
    cin>>a[i];
  }
  
  ll suma=0;
  priority_queue<ll,vector<ll>,greater<ll> > qa;
  rep(i,n){
    suma+=a[i];
    qa.push(a[i]);
  }
  ak[0]=suma;
  rep(k,n){
    suma+=a[n+k];
    qa.push(a[n+k]);
    ll l = qa.top(); qa.pop();
    suma-=l;
    ak[k+1]=suma;
  }

  ll sumb=0;
  priority_queue<ll> qb;
  rep(i,n){
    sumb+=a[2*n+i];
    qb.push(a[2*n+i]);
  }
  bk[0]=sumb;

  rep(k,n){
    sumb+=a[2*n-k-1];
    qb.push(a[2*n-k-1]);
    ll l = qb.top(); qb.pop();
    sumb-=l;
    bk[k+1]=sumb;
  }

  rep(i,n+1){
    ans = max(ans,ak[i]-bk[n-i]);
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 10996
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int a, b, c, phase, phaseMax;
    phase = 1;

    cin >> phaseMax;
    while(cin >> a >> b >> c) {
        a = pow(a, 2);
        b = pow(b, 2);
        c = pow(c, 2);

        cout << ((a + b == c || b + c == a || c + a == b) ? "YES" : "NO") << endl;

        if(phase++ >= phaseMax) break;
    }

    return 0;
}


Measured memory_bytes: 3072
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

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






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

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

    int x = a + b;; 
    if (x < a - b)
    	x = a - b;

    if (x < a * b)
    	x = a * b;

    cout << x;



    return 0;
}


Measured memory_bytes: 3572
h,w,k=map(int,input().split())
li=[list(input()) for i in range(h)]
ans=[]

num=1

#まず、最初の行からn行目までいちごがない場合についての処理を行う。
#その場合は、「いちごがない行」については全てデリートしてしまい、全ての処理が終わった後の先頭の行をコピーしたものを削除した行数文その前に貼り付ける処理をする。

count=0

for i in li[:]:
  if "#" not in i: #いちごがない場合はその行をデリートして、カウントを足す
    li.remove(i)
    count+=1
  else:
    break

h-=count

#一行目からいちごがある場合
for i in range(h):
  templi=li[i]
  ansli=[]
  ichigo=templi.count("#")
  #その行にいちごがある場合とない場合について処理を分ける
  #ある場合
  if ichigo!=0:
    tempnum=0
    for j in range(w):
      if templi[j]!="#":
        ansli.append(tempnum)
      elif templi[j]=="#" and tempnum!=ichigo-1:
        ansli.append(tempnum)
        tempnum+=1
      else:
        ansli.append(tempnum)
    #最後に、その行のリスト全体にnumを足し、numもtempnum+1だけ増やす。
    for j in range(w):
      ansli[j]+=num
    num+=tempnum+1
    ans.append(ansli)
  #ない場合 前の行(ansli[i-1])をそのままコピーする。
  else:
    ans.append(ans[i-1])

sentou=ans[0]

#最初の数行空白のケースは、最初に削除した行数文足す
for i in range(count):
  ans.insert(0,sentou)

for i in ans:
  print(*i)

Measured memory_bytes: 8352
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <math.h>
#include <algorithm>
#define rep(i,n) for(int i=0; i < (n); i++)
#define INF 1001001
using namespace std;


int main(){
  int n, x, t;
  cin >> n >> x >> t;
  if(n%x==0){
    cout << n/x *t << endl;
  }else{
    cout << (n/x +1)*t << endl;
  }
  

  
}

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

int main() {
  int D;
  cin>>D;
  if(D==22) cout<<" Christmas Eve Eve Eve"<<endl;
  if(D==23) cout<<" Christmas Eve Eve"<<endl;
  if(D==24) cout<<" Christmas Eve"<<endl;
  if(D==25) cout<<" Christmas"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int count=0;
  string S,ans="YES";
  cin>>S;
  rep(i,0,S.size()){
    if(S[i]=='x')
      count++;
  }
  if(count>=8)
    ans="NO";
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
/*c++11*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

int card=-1;

void print(vector<int> *a,vector<int> *b){
  
  cout<<"card:"<<card<<endl;
  printf("a:%lu,b:%lu\n",a->size(),b->size());

  cout<<"a:";
  for(auto ix:*a)
    cout<<ix<<" ";
  cout<<endl;

  cout<<"b:";
  for(auto iy:*b)
    cout<<iy<<" ";
  cout<<endl;
  cout<<endl;

}

int main(int args, char *argc[]){
  int n;
  vector<int> a;
  vector<int> b;

  while(cin>>n,n){
    a.clear();
    b.clear();
    for(int i=0;i<n;i++){
      int tmp;
      cin>>tmp;
      a.push_back(tmp);
    }
    sort(a.begin(),a.end());
    int ia=0;
    for(int i=1;i<=2*n;i++){
      if(i==a[ia]){
        ia++;
        continue;
      }
      b.push_back(i);
    }
    sort(b.begin(),b.end());

//    print(&a,&b);

    card=a[0];
    bool flaga=false;
    bool flagb=false;
    while(!a.empty() && !b.empty()){

      flaga=false;
      //b passed the round
      if(flagb==false)
        card=-1;
      for(unsigned ix=0;ix!=a.size();ix++){
        if(a[ix]>=card){
          card=a[ix];
          a.erase(a.begin()+ix);
          flaga=true;
          break;
        }
      }

//      cout<<"after a;\n";
//      print(&a,&b);
      
      if(a.empty() || b.empty())
        break;

      flagb=false;
      //a passed the round
      if(flaga==false)
        card=-1;
      for(unsigned ix=0;ix!=b.size();ix++){
        if(b[ix]>card){
          card=b[ix];
          b.erase(b.begin()+ix);
          flagb=true;
          break;
        }
      }

//      cout<<"after b;\n";
//      print(&a,&b);
    }//while

    cout<<b.size()<<endl<<a.size()<<endl;
  }

  return 0;
}


Measured memory_bytes: 3004
import math

def comb(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

nums = list(map(int, input().split()))

if nums[0] <= 1 and nums[1] <= 1:
  print(0)
elif nums[1] <= 1:
  print(comb(nums[0], 2))
elif nums[0] <= 1:
  print(comb(nums[1], 2))
else:
  print(comb(nums[0], 2) + comb(nums[1], 2))


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

using namespace std;

const int MAXN = 1000 * 1000 + 10;

int arr[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //cout << fixed << setprecision(10);

    int n, x, t;
    cin >> n >> x >> t;
    cout << ((n/x) + min(n%x,1)) * t<<endl;

    return 0;
}



Measured memory_bytes: 3604
<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$a_head = substr($a, 0, 1);
$b_head = substr($b, 0, 1);
$c_head = substr($c, 0, 1);
echo strtoupper($a_head . $b_head . $c_head);


Measured memory_bytes: 16264
#include<stdio.h>
long long a[300000];
long long fab(long long a)
{
    if(a>=0)
        return a;
    else return -a;
}
int main(void)
{
    long long N,m=0,n,p,q,l,s=0;
    scanf("%lld",&N);
    for(n=0;n<N;n++)
    {
        scanf("%lld",&a[n]);
        s=s+a[n];
    }
    p=fab(a[0]-s/2);
    for(n=0;n<N-1;n++)
    {
        m=m+a[n];
        if(fab(m-s/2)<=p) {l=m;p=fab(m-s/2);}
    }
    q=l-(s-l);
    printf("%lld",fab(q));
    return 0;

}

Measured memory_bytes: 1664
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N, M = in.nextInt
  val As = Array.fill(N)(in.nextLong)
  val mods = As.scanLeft(0L)((z, i) => (z + i) % M)
  val sum = mods.groupBy(identity).map{ case (_, l) =>
    l.size.toLong * (l.size - 1) / 2
  }.sum
  println(sum)
}

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

int main(){
    int N;
    cin >> N;
    int H[N];
    for(int i=0;i<N;i++) cin >> H[i];
    int ans =0;
    int M =0;
    for(int i=0;i<N;i++){
        if(H[i]>=M) ans++;
        M = max(M,H[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int A,B,C,D,X,Y;
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    scanf("%d",&D);
    if(A>B)X=B;
    else X=A;
    if(C>D)Y=D;
    else Y=C;
    printf("%d\n",X+Y);
    return 0;
}

Measured memory_bytes: 128