akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using ll = long long;
using namespace std;

int main(void) {
    int n, k;
    cin >> n >> k;

    vector<ll> x(n);

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

    // exhaustive search
    ll minv = 1LL<<60;
    // cout << "init" << minv << endl;
    for(int i = 0; i + k - 1 < n; ++i) {

        // cout << i << endl;

        ll left = x[i];
        ll right = x[i+k-1];

        // cout << "l:" << left  << endl;
        // cout << "r:" << right << endl;

        if (left < 0 && right < 0) {
            // ここが悪かった
            minv = min({minv, abs(left)});
            // minv = min (minv, min(abs(left),abs(right))+right-left);
            
        } else if (left >=0 && right >= 0) {
            minv = min({minv, right});
            // minv = min (minv, min(abs(left),abs(right))+right-left);

        } else {
           minv = min({minv, min({2*abs(left)+abs(right), 2*abs(right)+abs(left)})});
            // minv = min (minv, min(abs(left),abs(right))+right-left);
        }

//        minv = min (minv, min(abs(left),abs(right))+right-left);
        // cout << "ans:" << (left < 0 && right >= 0 ? 2 * llabs(left)+llabs(right) : right) << endl;
        // cout << "minv:" << minv << endl;
    }

    cout << minv << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
  cin>>n>>k;
  int A[1005];
  for(int i=0 ; i<n ; i++)
  {
    cin>>A[i];
    
  }
  sort(A,A+n);
  int mnposs=0;
  for(int i=0 ; i<k ; i++)
  {
    mnposs+=A[i];
  }
  cout<<mnposs;
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3576
def d_11(N, A):  # N:整数の種類, A:数列
    M = 10**9 + 7  # 求めた解の剰余をこれで取る

    # 重複した数のインデックスを求める
    from collections import Counter
    c = Counter(A).most_common(n=1)[0][0]  # 重複した整数の値を取得
    index = [i for i, x in enumerate(A) if x == c]  # 重複した整数のインデックス
    l = index[0] + 1
    r = index[1] + 1

    # フェルマーの小定理を用いてコンビネーションを効率よく計算
    factrial = [1] * (N + 2)  # 0~N+1までの階乗のテーブルを作る
    for k in range(1, N + 2):
        factrial[k] = (factrial[k - 1] * k) % M

    fact_inv = [1] * (N + 2)
    fact_inv[N + 1] = pow(factrial[N + 1], M - 2, M)
    for k in range(N, -1, -1):
        fact_inv[k] = (fact_inv[k + 1] * (k + 1)) % M

    def nCr(n, r, M):
        if n < 0 or r < 0 or n < r:
            return 0
        else:
            return (factrial[n] * fact_inv[r] * fact_inv[n - r]) % M

    ans = ''
    for k in range(1, N + 2):
        ans += '{}\n'.format((nCr(N + 1, k, M) -
                              nCr((l - 1) + (N + 1 - r), k - 1, M)) % M)
    return ans[:-1]

N = int(input())
A = [int(i) for i in input().split()]
print(d_11(N, A))

Measured memory_bytes: 18976
// RAM RAM

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define mp make_pair
#define arrayin(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define N 55

using namespace std;
string d[4]={"dream", "dreamer", "erase", "eraser"};

bool isPos(string &a,int idx){
	if(idx>=a.length()){
		return true;
	}
	string s1=a.substr(idx,5);
	string s2=a.substr(idx,7);
	string s3=a.substr(idx,6);

	if(s2==d[1]){
		if(isPos(a,idx+7)){
			return true;
		}
	}

	if(s3==d[3]){
		if(isPos(a,idx+6)){
			return true;
		}
	}

	if(s1==d[0] || s1==d[2]){
		if(isPos(a,idx+5)){
			return true;
		}
	}
	
	return false;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
    string a;cin>>a;
    if(isPos(a,0)){
    	cout<<"YES"<<endl;
    }else{
    	cout<<"NO"<<endl;
    }

	return 0;
}

Measured memory_bytes: 4944
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = (a); i < (b); ++i) 

const int MAX_N = 10;
bool graph[MAX_N][MAX_N];
int N, M;
bool vis[MAX_N];

int tansaku(int cur) {
    int cnt = 0;
    bool flg = true;
    REP(i, 0, N) if(!vis[i]) flg = false;
    if(flg) { return 1; }

    REP(i, 0, N) if(graph[cur][i]) {
        if(vis[i]) continue;
        vis[i] = true;
        cnt += tansaku(i);
        vis[i] = false;
    }
    return cnt;
}

void solve(){
    vis[0] = true;
    cout << tansaku(0) << endl;
}

int main()
{
    scanf("%d %d", &N, &M);
    REP(i, 0, M) {
        int a, b;
        scanf("%d %d", &a, &b);
        --a, --b;
        graph[a][b] = graph[b][a] = true;
    }
    solve();
    return 0;
}

Measured memory_bytes: 384
#!/usr/bin/perl -w
chomp($hoge=<>);
($n,$yen)=split(/ /,$hoge);
$res=0;
LOOP: for($x=0;$x<=$n;$x++){
    for($y=0;$y<=$n-$x;$y++){
        $z=$n-$x-$y;
        $sum=10000*$x+5000*$y+1000*$z;
        if($sum == $yen){
            print "$x $y $z\n";
            $res=1;
            last LOOP;
        }
    }
}

if($res==0){
    print "-1 -1 -1";
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
 
N=int(input())

ans = ""
while N>0:
    N -= 1
    ans += chr(ord("a")+N%26)
    N //= 26

print(ans[::-1])

Measured memory_bytes: 77440
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main() {
	int a,b,c,d,k; cin>>a>>b>>c>>d>>k;
	if(b>d) c--, d+=60;
	if(a>c) c+=24;
	int h,m; h=c-a, m=d-b;
	if(m<k) m+=60, h--;
	cerr<<a SP b SP c SP d SP h SP m<<endl;
	cout<<max(0,h*60+m-k)<<endl;

	return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int asc(const void* a, const void* b) {
    return *(char*)b - *(char*)a;
}
int main() {
    int k, x;
    scanf("%d %d", &k, &x);
    if (500 * k >= x)printf("Yes");
    else printf("No");
   
    return 0;
}





Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int cnt[100100] = {};
    long long sum = 0;
    for (int i = 0; i < n; i++) { int a; cin >> a; cnt[a]++; sum += a; }
    int q; cin >> q;
    while (q--) {
        int b, c; cin >> b >> c;
        int k = cnt[b];
        cnt[b] = 0;
        cnt[c] += k;
        sum = sum + (long long)(c - b) * k;
        cout << sum << endl;
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  double t, x;
  cin >> t >> x;
  printf("%.9lf\n", t / x);
  return 0;
}


Measured memory_bytes: 256
//#define NDEBUG

#pragma region cp_template

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  return a < b ? b - a : a - b;
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b)
    a = b;
}
template <class F> class rec_lambda {
  F f;

public:
  rec_lambda(F &&f) : f(std::move(f)) {}
  template <class... Args> auto operator()(Args &&... args) const {
    return f(*this, std::forward<Args>(args)...);
  }
};
template <class F> auto make_rec(F &&f) { return rec_lambda<F>(std::move(f)); }
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}
constexpr char eoln = '\n';
template <class T> T ceildiv(const T &l, const T &r) {
  return l / r + (l % r != 0 ? 1 : 0);
}

} // namespace n91

#pragma endregion cp_template

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  const usize n = scan<usize>();
  const usize k = scan<usize>();
  std::vector<u32> a(n);
  for (auto &e : a) {
    std::cin >> e;
  }
  for (const usize i : rep(k, n)) {
    std::cout << (a[i - k] < a[i] ? "Yes" : "No") << eoln;
  }
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 4048
def loop(rat, r)
  a, b, d = rat.numerator, rat.numerator * 10, rat.denominator
  arr = Array.new
  phi = phi(d)
  [r, phi].min.times do
    arr << b / d
    b = (b % d) * 10
  end
  while a != b and arr.size < r
    arr << b / d 
    a, b = (a % d) * 10, (b % d) * 10
  end
  if arr.size == r
    return ((r == 1) ? "1." : "0.") + arr.join
  else
    return ((r == 1) ? "1." : "0.") + arr[0...-phi].join.ljust(r, arr[-phi..-1].join)
  end
end
def main(input = STDIN)
  $s = [Rational(0,1)]
  3.times do |t|
    s(5000 * (t + 1))
  end
  while (n, k, m, r = input.gets.split(" ").map(&:to_i)) != [0, 0, 0, 0] # !> assigned but unused variable - k
    puts loop((1 + m * s(n - 1)) / n, r)
  end
end
def phi(n)
  result = n
  result /= 2 if n % 2 == 0
  n /= 2 while n % 2 == 0
  prime = 3
  while n != 1
    if n % prime == 0
      result = result * (prime - 1) / prime
      n /= prime while n % prime == 0
    end
    prime += 2
  end
  return result
end
 
def s(n)
  $s[n] = Rational(1, n) + s(n - 1) unless $s[n]
  return $s[n]
end
main

Measured memory_bytes: 67208
import sys

if __name__ == '__main__':
    A, B, C, D = map(int, input().split())
    cnt = 0
    while A > 0 and C > 0:
        if cnt % 2 == 0:
            C -= B
        else:
            A -= D
        cnt += 1

    print('Yes' if A > 0 else 'No')


Measured memory_bytes: 9168
from sys import stdin

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))


c=a

max=0
"""
for i in range(n+1):
    max+=a[i]"""

for i in range(n):
    if c[i]>=b[i]:
        max+=b[i]
    else:
        max += c[i]
        
        if (b[i]-c[i])<a[i+1]:
            max += b[i]-c[i]
            c[i+1]=a[i+1]-b[i]+c[i]
        else:
            max+=a[i+1]
            c[i+1]=0


print(max)

Measured memory_bytes: 19156
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n: usize = read_as_vec()[0];
    let a = read_as_vec::<f64>();

    let avg = (a.iter().sum::<f64>()/(n as f64)).round() as i64;

    println!("{}", a.into_iter().map(|x| x as i64).map(|x| (x-avg)*(x-avg)).sum::<i64>());
}


Measured memory_bytes: 4476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
main(){
    int k;string s;
    cin>>k>>s;
    int len=s.size();
    if(len<=k) cout<<s;
    else{
        for(int i=0;i<k;i++) cout<<s[i];
        cout<<"...";
    }
}


Measured memory_bytes: 3624
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long int ll;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define MOD 1000000007
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);  
//*s.find_by_order(p)   returns the value of pth largest starting from 0 
//s.order_of_key(p)   returns no. of items that are strictly < p 
//string bin = bitset<64>(m).to_string();     convert decimal m to binary 
int main()
{
      fast;ll t;t=1;
      while(t--)
      { 
            ll a,b,c,d,p;
            cin>>a>>b>>c>>d;
            p=max({b*d,a*c,a*d,b*c});
            if((a<=0 && b>=0) || (c<=0 && d>=0)){
                  if(p<0){p=0;}
            }
            cout<<p<<"\n";


      }
}

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

int first_digit(int n){
  if(n >= 100000) return (n/100000);
  if(n >= 10000) return (n/10000);
  if(n >= 1000) return (n/1000);
  if(n >= 100) return (n/100);
  if(n >= 10) return (n/10);
  return n;
}
  

int main(){
  int n;
  cin >> n;
  
  int cnt=0;
  VVI t(9, VI(9,0));
  
  rep2(i,1,n+1){
    int f = first_digit(i);
    int l = i%10;
    
    if(l==0) continue;
    if(l==f) cnt++;
    
    cnt += 2*t[l-1][f-1];
    t[f-1][l-1]++;
  }
  
  cout << cnt << endl;
  
  return 0;
}

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

vector<int> get_primes(int n) {
  vector<bool> is_prime(n, true);
  for (int i = 2; i * i <= n; i++)
    for (int j = i * i; j <= n; j += i)
      is_prime[j] = false;

  vector<int> primes;
  for (int i = 2; i <= n; i++)
    if (is_prime[i])
      primes.push_back(i);
  return primes;
}

vector<pair<long long, int>> factorize(long long n, const vector<int>& primes) {
  vector<pair<long long, int>> prime_factors;
  for (int prime : primes) {
    int t = 0;
    while (n % prime == 0) {
      t++;
      n /= prime;
    }

    if (t)
      prime_factors.emplace_back(prime, t);
  }

  if (n > 1) prime_factors.emplace_back(n, 1);
  return prime_factors;
}

vector<long long> get_factors(vector<pair<long long, int>> prime_factors)
{
  vector<long long> factors = {1};
  for (auto p : prime_factors) {
    vector<long long> t;
    for (auto f : factors) {
      t.push_back(f);
      for (int i = 0; i < p.second; i++) {
        f *= p.first;
        t.push_back(f);
      }
    }
    factors = t;
  }

  return factors;
}

int main()
{
  long long n;
  scanf("%lld", &n);
  
  auto primes = get_primes((int)ceil(sqrt(n)));
  
  auto n_1_prime_factors = factorize(n - 1, primes);
  long long n_1_factor_count = 1;
  for (auto p : n_1_prime_factors)
    n_1_factor_count *= p.second + 1;
  
  long long ans = n_1_factor_count - 1;
  auto n_prime_factors = factorize(n, primes);
  auto n_factors = get_factors(n_prime_factors);
  for (auto f : n_factors) {
    if (f == 1) continue;
    auto t = n;
    while (t % f == 0) t /= f;
    if (t % f == 1) ans++;
  }

  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 1020
/**
 *    author:  FromDihPout
 *    created: 2020-08-15
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    vector<char> letter = {'M', 'A', 'R', 'C', 'H'};
    const int L = letter.size();
    
    int n;
    cin >> n;
    vector<int> cnt(L);
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int i = 0; i < L; i++) {
            if (s[0] == letter[i]) {
                cnt[i]++;
                break;
            }
        }
    }
    
    long long ans = 0;
    for (int i = 0; i < L; i++) {
        for (int j = i + 1; j < L; j++) {
            for (int k = j + 1; k < L; k++) {
                ans += (long long) cnt[i] * cnt[j] * cnt[k];
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>
#include <limits>

using namespace std;
vector<vector<int>> graph;
vector<long long> subcnt;

int main() {
  int n, Q;
  scanf("%d%d", &n, &Q);
  graph.resize(n);
  for (int i = 0; i < n-1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  subcnt.resize(n);
  for (int i = 0; i < Q; i++) {
    int p, x;
    scanf("%d%d", &p, &x);
    p--;
    subcnt[p] += x;
  }
  queue<int> q;
  vector<bool> visit(n);
  q.push(0);
  visit[0] = true;
  while (!q.empty()) {
    int cur = q.front(); q.pop();
    for (auto next : graph[cur]) {
      if (visit[next]) continue;
      subcnt[next] += subcnt[cur];
      visit[next] = true;
      q.push(next);
    }
  }
  for (int i = 0; i < n; i++) {
    printf("%lld%c", subcnt[i], " \n"[i + 1 == n]);
  }
  return 0;
}


Measured memory_bytes: 16372
#include<stdio.h>

int main( void ) 
{
	int n;
	int num;
	int tRi;
	int max,tnum;	
	int i,j;

	scanf( "%d", &n );
	
  	max=1-1000000000;
	tRi=1000000000;
	j=0;
	for( i=0; i<n; i++ ) {
  		scanf( "%d", &num );
  		tnum=num-tRi;
   		if(  j && max <= tnum ) {
   			max=tnum;
   		}
   		if( num <= tRi ) {
   			tRi=num;
   	   		j=1;		
   		}   		
  	}
	
	printf( "%d\n", max );

	return 0;
}

Measured memory_bytes: 596
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YY cout << "Yes" << endl;
#define NN cout << "No" << endl;
#define ve vector
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
// *max_element(all(d))
int solve(){
  ll x,y,a,b,c;
  cin >> x >> y >> a >> b >> c;
  priority_queue<ll,vector<ll>,greater<ll>>p,q;
  priority_queue<ll>r;
  vector<ll>v(a),vv(b);
  rep(i,a)cin >> v[i];
  sort(all(v));
  reverse(all(v));
  rep(i,x)p.push(v[i]);
  rep(i,b)cin >> vv[i];
  sort(all(vv));
  reverse(all(vv));
  rep(i,y)q.push(vv[i]);
  rep(i,c){
    int tmp;
    cin >> tmp;
    r.push(tmp);
  }
  rep(i,1000000){
    if(r.empty())break;
    ll aa = p.top(),bb = q.top(),cc = r.top();
    if(aa > bb){
      if(cc > bb){
        q.pop();
        q.push(cc);
        r.pop();
      }
      else break;
    }
    else{
      if(cc > aa){
        p.pop();
        p.push(cc);
        r.pop();
      }
      else break;
    }
  }
  ll ans = 0;
  rep(i,x){
    ans += p.top();
    p.pop();
  }
  rep(i,y){
    ans += q.top();
    q.pop();
    
  }
  cout << ans << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}


Measured memory_bytes: 4724
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

bool DFS(int V,int C,vector<vector<int> > &GRAPH,vector<int> & color)
{
  color[V] = C;
  for (int i = 0; i < GRAPH[V].size(); i++)
  {
    int nV = -1;
      // DEBUG(nV);
    if(GRAPH[V][i] == 1)
    nV = i;
    if(nV == -1)continue;

    if(color[nV] != -1)
    {
      if(color[nV] == C)return false;
      continue;
    }
    else
    if(!DFS(nV,C^1,GRAPH,color))return false;
  }
  return true;
}
void solve(void)
{
  int N;cin>>N;
  vector<vector<int> > GRAPH (N,vector<int>(N,0));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      char x;
      cin>>x;
      GRAPH[i][j] =(int)(x - '0');
    }
  }
  
  vector<int> color(N,-1);
  if(DFS(0,0,GRAPH,color) == 0)
  {
    cout<<-1<<endl;
    return;
  }
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      if(GRAPH[i][j] == 0)GRAPH[i][j] = INF;
      if(i == j )GRAPH[i][j] = 0;
    }
    
  }

  
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      for (int k = 0; k < N; k++)
      {
        GRAPH[j][k] = min(GRAPH[j][k],GRAPH[j][i] + GRAPH[i][k]);
      }
    }
  }
  int ANS = 0;
  // DEBUG(GRAPH);
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      chmax(ANS,GRAPH[i][j] + 1);
    }
    
  }
  cout<<ANS<<endl;
  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);

std::cout << std::fixed;
std::cout << std::setprecision(9);
solve();

return 0;
}


Measured memory_bytes: 640
#include<vector>
#include<iostream>
using namespace std;
template <class data_t>
class dice{
public:
	vector<data_t> field;
	dice(vector<data_t> v);
	void roll(char ch);
	data_t top(){return field[0];}
};
template <class data_t>
dice<data_t>::dice(vector<data_t> v){
	typename vector<data_t>::iterator vi = v.begin();
	while(vi!=v.end()){
		field.push_back(*vi);
		vi++;
	}
}
template <class data_t>
void dice<data_t>::roll(char ch){
	data_t tmp;
	switch(ch){
		case 'E':
			tmp = field[0];
			field[0] = field[3];
			field[3] = field[5];
			field[5] = field[2];
			field[2] = tmp;
			break;
		case 'N':
			tmp = field[0];
			field[0] = field[1];
			field[1] = field[5];
			field[5] = field[4];
			field[4] = tmp;
			break;
		case 'S':
			tmp = field[0];
			field[0] = field[4];
			field[4] = field[5];
			field[5] = field[1];
			field[1] = tmp;
			break;
		case 'W':
			tmp = field[0];
			field[0] = field[2];
			field[2] = field[5];
			field[5] = field[3];
			field[3] = tmp;
			break;
	}
	return;
}

int main(){
	vector<int> v(6);
	string str;
	string::iterator si;
	cin >> v[0] >> v[1] >> v[2] >> v[3] >> v[4]>> v[5];
	cin >> str;
	dice<int> d(v);
	si = str.begin();
	while(si != str.end()){
		d.roll(*si);
		si++;
	}
	cout << d.top() << endl;
	return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>
#define N1 2000
#define N2 200

int main(void){
    int i, j, q, n;
    int A[20];
    int m[N2];
    int f[20][2001];
    int max = -1;
    int s[100];
    int cnt=1;


    scanf("%d", &n);

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

    for(i=0; i<20; i++){
        for(j=0; j<2001; j++){
            f[i][j]=0;
        }
    }

    scanf("%d", &q);

    for(i=0; i<q; i++) {
        scanf("%d", &m[i]);
        if(m[i] > max){
            max = m[i];
        }
    }

    f[0][0] = 1;

    f[0][A[0]]= 1;

    for(i=1; i<n; i++) {
        for(j=0; j<=max; j++) {
            if(f[i-1][j] == 1){
                f[i][j]=1;
            }
            else if(f[i-1][j-A[i]] == 1){
                f[i][j]=1;
            }
        }
    }

    for(i=0; i<q; i++){
        if(f[n-1][m[i]] == 1)
            puts("yes");
        else
            puts("no");
        
    }

    return 0;
}


Measured memory_bytes: 2092
main(){
  long long int a[51],b;
  int n,p,d,x;
  int m[31][51];
  for(;scanf("%d",&n),n;){
    memset(m,0,sizeof(m));
    for(p=0;p<n;a[p]=(long long int)1<<p,p++)
      for(scanf("%d",&x);x;x--)scanf("%d",&d),m[d][p]=1;
    for(d=1;d<31;d++){
      for(b=p=0;p<n;p++)if(m[d][p])b|=a[p];
      for(p=0;p<n;p++)
        if(m[d][p]){
          a[p]=b;
//printf("%d %d %I64d\n",d,p,a[p]);
          if(a[p]==((long long int)1<<n)-1){printf("%d\n",d);goto s;}
        }
    }
//printf("---%d %I64d\n",n,(long long int)1<<n);
    puts("-1");
    s:;
  }
  return 0;
}

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

int main(){
  int N,count;
  cin>>N;
  count=0;
  int B=1;
  vector<int> A(N);
  for(int i=0;i<N;i++){
     cin>>A.at(i);
  }
  for(int i=0;i<=N;i++){
    if(B==2){
    cout<<count<<endl;
    break;
    }
    
    B=A.at(B-1);
    count++;
      if(i==N){
        cout<<-1<<endl;
      }
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <queue>

using namespace std;

const int kD[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const int kMaxN = 1001;

struct E {
  int x, y;
} q[kMaxN * kMaxN], d;
char c[kMaxN][kMaxN];
int a[kMaxN][kMaxN];
int n, m, h, t, _t;

void T(int x, int y, int d) {
  if (x < 1 || x > n || y < 1 || y > m || c[x][y] == '#' || a[x][y]) {
    return;
  }
  a[x][y] = d;
  q[++t] = {x, y};
}

int main() {
  cin >> n >> m >> q[0].x >> q[0].y >> d.x >> d.y;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> c[i][j];
    }
  }
  a[q[0].x][q[0].y] = 1;
  for (h = 0, t = 0; h <= t; h = _t + 1) {
    for (int i = h; i <= t; i++) {
      for (int j = 0; j <= 3; j++) {
        T(q[i].x + kD[j][0], q[i].y + kD[j][1], a[q[i].x][q[i].y]);
      }
    }
    _t = t;
    for (int i = h; i <= _t; i++) {
      for (int j = q[i].x - 2; j <= q[i].x + 2; j++) {
        for (int k = q[i].y - 2; k <= q[i].y + 2; k++) {
          T(j, k, a[q[i].x][q[i].y] + 1);
        }
      }
    }
  }
  cout << a[d.x][d.y] -1;
  return 0;
}


Measured memory_bytes: 12236
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(s...)  fprintf(stderr, s)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }


int main() {
    LL A, B, C;
    scanf("%lld%lld%lld", &A, &B, &C);


    LL ans = A * B;
    if (A % 2) amin(ans, B * C);
    else amin(ans, 0LL);

    if (B % 2) amin(ans, A * C);
    else amin(ans, 0LL);

    if (C % 2) amin(ans, A * B);
    else amin(ans, 0LL);

    printf("%lld\n", ans);


    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<list>
#include<set>
using namespace std;

int main(){
  int n,a,b,c,A,B,C;
  scanf("%d",&n);

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



Measured memory_bytes: 3144
#include <stdio.h>
#include<string.h>
int main()
{
	char s[10];
    int l,i,x;
    while(scanf("%s",&s)!=EOF)
    {
    	x=0;
    	l=strlen(s);
    	for(i=0;i<l;i++)
    	{
    		if(s[i]=='A'&&s[i+1]=='C')
    		{
    			printf("Yes\n");
    			x=1;
    			break;
			}
		}
		if(x==0) printf("No\n");
	}
    return 0;
}

Measured memory_bytes: 128
from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
from  itertools import accumulate

def get_int():return int(stdin.readline().strip())
def get_tuple():return map(int, stdin.readline().split())
def get_list():return list(map(int, stdin.readline().split()))

n = get_int()
ls = get_list()
mod = 10**9+7
pref_sum = list(accumulate(ls))

ans = 0
for i in range(1,n):
    ans = (ans+ls[i]*(pref_sum[i]-ls[i]))%mod
print(ans)

Measured memory_bytes: 32168
#include <stdio.h>

void sousa(int* a, int* b) {
	int t = *a; *a = *b; *b = t;
}

int main(void) {
	int X, Y, Z;
	if (scanf("%d%d%d", &X, &Y, &Z) != 3) return 1;
	sousa(&X, &Y);
	sousa(&X, &Z);
	printf("%d %d %d\n", X, Y, Z);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

const int MAX = 210000;
int N;
vector<int> G[MAX];

bool seen[MAX];
int grundy[MAX];

int thev = -1, thenum = -1;

bool lastcheck() {
	set<int> se;
	for (auto nv : G[thev]) {
		se.insert(grundy[nv]);
	}
	int res = 0;
	for (res = 0;; ++res) {
		if (!se.count(res)) break;
	}

	if (res == thenum) return true;
	else return false;
}

int rec(int v, bool up = false) {
  seen[v] = true;

  bool iscy = false;
  for (auto nv : G[v]) {
		if (grundy[nv] != -1) continue;
		if (seen[nv]) {
		 iscy = true;
		 continue;
		}
		rec(nv, up);
  }

  set<int> se;
  for (auto nv : G[v]) {
		if (grundy[nv] == -1 && seen[nv]) continue;
		se.insert(grundy[nv]);
  }
  int res = 0;
  for (res = 0;; ++res) {
		if (!se.count(res)) break;
  }
  
	if (iscy && up) {
		++res;
		for (;; ++res) {
			if (!se.count(res)) break;
		}
	}

	if (iscy) {
		thev = v;
		thenum = res;
	}

	//cout << v << ": " << res << endl;
	  
	return grundy[v] = res;
}


int main() {
  while (cin >> N) {
	for (int i = 0; i < MAX; ++i) G[i].clear();
	for (int i = 0; i < N; ++i) {
	  int a;
	  cin >> a;
	  --a;
	  G[a].push_back(i);
	}
	bool res = false;
	
	memset(seen, 0, sizeof(seen));
	memset(grundy, -1, sizeof(grundy));
	thev = -1, thenum = -1;
	for (int v = 0; v < N; ++v) {
	  if (grundy[v] != -1) continue;
	  rec(v, false);
	}
	//COUT(thev);
	//COUT(thenum);
	if (lastcheck()) res = true;

	memset(seen, 0, sizeof(seen));
	memset(grundy, -1, sizeof(grundy));
	thev = -1, thenum = -1;
	for (int v = 0; v < N; ++v) {
	  if (grundy[v] != -1) continue;
	  rec(v, true);
	}
	//COUT(thev);
	//COUT(thenum);
	if (lastcheck()) res = true;
	
	if (res) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
  }
}







Measured memory_bytes: 34944
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int N,K;string s;cin>>N>>s>>K;
  for(char p:s){
    if(p==s[K-1])cout<<p;
    else cout<<'*';
  }
  cout<<endl;
}


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

int main() {
  int A;
  cin >> A;
  
  for (int i = 0; i < A; i++) {
	string j;
    cin >> j;
    
    if (j == "Y") {
      cout << "Four" << endl;
      break;
    }
    else if (i == A - 1) {
      cout << "Three" << endl;
    }
	else {
      continue;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100001
#define NIL -1

struct Node{
  int p,l,r;
};
struct Node T[N];

int CalcDepth(int id){
  if(T[id].p==NIL)return 0;
  return CalcDepth(T[id].p)+1;
}

int main(){
  int n,i,j,id,k,c,pr;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=NIL;
    T[i].l=NIL;
    T[i].r=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&id,&k);
    for(j=0;j<k;j++){    
      scanf("%d",&c);
      if(j==0) {
	T[id].l=c;
	T[c].p=id;
	pr=c;
      }else{
	T[pr].r=c;
	T[c].p=id;
	pr=c;     
      }
    }
  }
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,T[i].p,CalcDepth(i));
    if(T[i].p==NIL) printf("root, ["); 
    else if(T[i].l==NIL) printf("leaf, [");
    else printf("internal node, [");
    if(T[i].l!=NIL){
      printf("%d", T[i].l);
      pr = T[i].l;
      while(T[pr].r!=NIL){
	printf(", %d", T[pr].r);
	pr = T[pr].r;
      }
    }
    printf("]\n");
  }
  return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const ll inf = 1e18 + 5;

struct UnionFind {
  vi parent, rank, count;
  UnionFind(const int nodeSize)
    : parent(nodeSize), rank(nodeSize, 1), count(nodeSize) {
    rep(i, nodeSize) parent[i] = i, count[i] = 1;
  }
  int find(int x) {
    if (parent[x] == x) return x;
    return parent[x] = find(parent[x]);
  }
  void unite(int x, int y) {
    int rx = find(x);
    int ry = find(y);
    if (rx == ry) return;
    if (rank[rx] < rank[ry]) swap(rx, ry);
    parent[ry] = rx;
    count[rx] += count[ry];
    if (rank[rx] == rank[ry]) ++rank[rx];
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  int num(int x) {
    return count[find(x)];
  }
};

struct Edge { int to, cost; };
vector<vector<Edge>> tree;
vl ans;
void dfs(int par, int now) {
  for (auto &edge : tree[now]) if (edge.to != par) {
    ans[edge.to] = ans[now] + edge.cost;
    dfs(now, edge.to);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  tree.resize(n);
  rep(i, n-1) {
    int u, v, w; std::cin >> u >> v >> w;
    u--, v--;
    tree[u].pb({v, w}), tree[v].pb({u, w});
  }
  ans.resize(n);
  ans[0] = 0;
  dfs(-1, 0);
  rep(i, n) std::cout << (ans[i]&1) << "\n";
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int cost[100001];
int h[100001];
int abs(int a) {
	if(a<0) return -a;
	return a;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, k;
	cin>>n>>k;
	for(int i = 0; i < n; ++i) {
		cin>>h[i];
	}
	cost[0] = 0;
	for(int i = 1; i < n; ++i) {
		cost[i] = 1000000000;
		for(int j = 1; j <= k && j <= i; ++j) {
			cost[i] = min(cost[i], cost[i-j] + abs(h[i] - h[i-j]));
		}
	}
	cout<<cost[n-1]<<"\n";
	return 0;
}


Measured memory_bytes: 4432
#include <iostream>

int main() {
  int n, x;
  std::cin >> n >> x;
  int M[110];

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

  int mini = 1e5+10;
  int count = 0;

  for(int i=0; i<n; ++i) {
    x -= M[i];
    count++;
    if(mini > M[i]) mini = M[i];
  }


  while(true) {
    if(x < mini) break;
    x -= mini;
    count++;
  }

  std::cout << count << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <unordered_map>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

UINT gcd(UINT a, UINT b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

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

const UINT mod = 1000000007;
const double pi = 3.141592653589793238462;
const INT intmax = 9223372036854775807;

UINT _PowMod(UINT x, UINT y, UINT _mod)
{
	if (y == 0)
	{
		return 1;
	}
	else if (y == 1)
	{
		return x % _mod;
	}
	else if (y % 2 == 0)
	{
		auto tmp = _PowMod(x, y / 2, _mod);
		return tmp * tmp % _mod;
	}
	else
	{
		auto tmp = _PowMod(x, y / 2, _mod);
		return (tmp * tmp % _mod) * x % _mod;
	}
}


UINT PowMod(UINT x, UINT y)
{
	return _PowMod(x, y, mod);
}

UINT getModInv(UINT N)
{
	return PowMod(N, mod - 2);
}

INT nCrMod(INT start, INT n, INT r)
{
	if (n < r)
	{
		return 0;
	}
	INT a = start;
	for (size_t i = n; i >= n - r + 1; i--)
	{
		a *= i;
		a %= mod;
	}
	for (size_t i = 1; i <= r; i++)
	{
		a *= getModInv(i);
		a %= mod;
	}
	return a;
}

INT nHrMod(INT start, INT n, INT r)
{
	return nCrMod(start, n + r - 1, r);
}

INT _nCrMod(INT start, INT n, INT r)
{
	if (n <= 0)
	{
		return 0;
	}
	return nCrMod(start, n, r);
}

struct uf
{
	vector<INT> p;

	uf(INT n) : p(n)
	{
		for (size_t i = 0; i < n; i++)
		{
			p[i] = i;
		}
	}

	INT rt(INT n)
	{
		return p[n] == n ? n : p[n] = rt(p[n]);
	}

	void un(INT n, INT m)
	{
		p[rt(n)] = p[rt(m)];
	}

	bool eq(INT n, INT m)
	{
		return rt(n) == rt(m);
	}
};

bool lineCol(INT a1x, INT a1y, INT a2x, INT a2y, INT b1x, INT b1y, INT b2x, INT b2y)
{
	auto ta = (b1x - b2x) * (a1y - b1y) + (b1y - b2y) * (b1x - a1x);
	auto tb = (b1x - b2x) * (a2y - b1y) + (b1y - b2y) * (b1x - a2x);
	auto tc = (a1x - a2x) * (b1y - a1y) + (a1y - a2y) * (a1x - b1x);
	auto td = (a1x - a2x) * (b2y - a1y) + (a1y - a2y) * (a1x - b2x);

	return tc * td < 0 && ta * tb < 0;
}

INT powInt(INT a, INT b)
{
	if (b == 0)
	{
		return 1;
	}
	if (b == 1)
	{
		return a;
	}
	INT tmp = powInt(a, b / 2);
	return (b % 2 == 1 ? a * tmp * tmp : tmp * tmp);
}

INT _sMod(string n, INT mod)
{
	INT k = (n[0] - '0') % mod;
	for (size_t i = 1; i < n.length(); i++)
	{
		k *= 10;
		k += (n[i] - '0');
		k %= mod;
	}
	return k;
}

#define forin(v, n)				\
for (size_t i = 0; i < n; i++)	\
{								\
	cin >> v[i];				\
}

#define vec(t, name, n)			vector<t> name(n)
#define vec_(t, name, n, init)	vector<t> name(n, init)

#define vec2(t, name, n, m)			vector<vector<t>> name(n, vector<t>(m))
#define vec2_(t, name, n, m, init)	vector<vector<t>> name(n, vector<t>(m, init))

struct xy
{
	INT x, y;
	xy() :x(0), y(0) {}
	xy(INT _x, INT _y) : x(_x), y(_y) {}
};

int main()
{
	INT n;
	cin >> n;
	cout << n * (n + 1) / 2 << endl;

	return 0;
}


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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
    ll n;
    cin >> n;
    vll w(n);

    ll total = 0;
    REP(i, n) {
      cin >> w[i];
      total += w[i];
    }

    ll min_omosa = INF;
    REP(i, n - 1) {
      ll omosa = 0;
      REP(j, i + 1) {
        omosa += w[j];
      } 
      min_omosa = min(min_omosa, abs(omosa - (total - omosa)));
    }


    COUT(min_omosa);

}



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

/*
3
1 2 3
*/


Measured memory_bytes: 3492
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define nl '\n'
typedef long long ll;
//////////////////////////////////////////////////////////////////////



int main(){
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  
  ll n,m;cin>>n>>m;
  n--;m--;
  cout << n*m << nl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{

    public static int number;
    public static int[] A=new int[1000];

    public static void main(String[] args)
    {
        
        Scanner scan=new Scanner(System.in);
        number=scan.nextInt();

        for(int i=0;i<number;i++){
            A[i]=scan.nextInt();
            if(i!=number-1) System.out.print(A[i]+" ");
            if(i==number-1) System.out.print(A[i]);
        }
        System.out.println();

        insertionSort();

    }

    public static void insertionSort()
    {
        int v,j=0;
        for(int i=1;i<=number-1;i++)
        {
            v = A[i];
            j=i-1;
            while(j>=0 && A[j]>v)
            {
                A[j+1]=A[j];
                j--;
            }
            A[j+1]=v;

            for(int l=0;l<number;l++)
            {
                if (l != number - 1) System.out.print(A[l] + " ");
                if (l == number - 1) System.out.print(A[l]);
            }
            System.out.println();
        }

    }
}

Measured memory_bytes: 31484
from math import factorial

N, M = map(int, input().split())
if abs(N-M) >= 2:
    print(0)
elif abs(N-M) == 1:
    print((factorial(N)*factorial(M)) % (10**9+7))
elif abs(N-M) == 0:
    print((factorial(N)*factorial(M)*2) % (10**9+7))

Measured memory_bytes: 5192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 114514
int main(){
    int D,G;
    cin>>D>>G;
    vector<int>p(D),c(D);
    for(int i=0;i<D;i++){
        cin>>p[i]>>c[i];
    }
    int bit_search=pow(2,D),ans=INF,sum,hoge;
    for(int i=0;i<=bit_search;i++){//何も使わないから全て使うまで全探査
        sum=0,hoge=0;
        for(int j=0;j<D;j++){
            if(i&(1<<j)){
                sum+=c[j]+p[j]*(j+1)*100;
                hoge+=p[j];
            }
        }
        int cnt=0,current=D-1;
        while(sum<G){
            if(!(i&(1<<current))&&cnt<p[current]){
                sum+=(current+1)*100;
                cnt++;
                hoge++;
            }
            else{
                current--;
                cnt=0;
            }
        }
        ans=min(hoge,ans);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,q;
    string s;
    cin>>n>>q>>s;
    vector<int> a(n);
    repi(i,1,n){
        a[i]=a[i-1];
        if(s[i-1]=='A'&&s[i]=='C') a[i]++;
    }
    vector<int> l(q),r(q);
    rep(i,q) cin>>l[i]>>r[i];
    rep(i,q){
        cout<<a[r[i]-1]-a[l[i]-1]<<endl;
    }
}

Measured memory_bytes: 4524