akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
int n;
long long res;
string s;
unordered_map<string, int> m;
int main() {
    DAU
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> s;
        sort(s.begin(), s.end());
        ++m[s];
    }
    for (const auto& P : m)
        res += 1LL * P.second * (P.second - 1) / 2LL;
    cout << res;
    PLEC
}


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

int n;
map<pair<int, int>, long> mp;

int front(int n) {
  while (n >= 10) {
    n /= 10;
  }
  return n;
}

int main() {
  cin >> n;
  long sum = 0;
  for (int i = 1; i <= n; ++i) {
    ++mp[make_pair(front(i), i % 10)];
  }
  
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      sum += mp[make_pair(i, j)] * mp[make_pair(j, i)];
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int a[100010];
    REP(i,N) cin >> a[i];
    int count[100010];
    REP(i,100010) count[i] = 0;
    REP(i,N){
        count[a[i]-1]+=1;
        count[a[i]]+=1;
        count[a[i]+1]+=1;
    }
    cout << *max_element(count, count+100001) << endl;
    return 0;
}

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

#define  ll long long
#define  il inline
#define INF 0x3f3f3f3f
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define dep(i,a,b) for(int i=(a);i>=(b);--i)

const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
const int maxm = 2e5 + 10;
const double PI = acos(-1.0);

char s[5];

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin >> s;
    if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) cout << "Bad" << endl;
    else cout << "Good";
    return 0;

}


Measured memory_bytes: 384
<?php

$input = trim(fgets(STDIN));
if(strpos($input, 'RRR') !== false){
  echo "3\n";
} else if(strpos($input, 'RR') !== false){
  echo "2\n";
} else if(strpos($input, 'R') !== false){
  echo "1\n";
} else {
  echo "0\n";
}


Measured memory_bytes: 16048
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;

int n, m, a[MAXN];
set<II> s;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,n) cin >> a[i];
    sort(a+1, a+n+1);

    int cnt = 1;
    FOR(i,2,n)
        if (a[i] == a[i-1]) cnt++;
        else {
            s.insert(II(a[i-1], cnt));
            cnt = 1;
        }
    s.insert(II(a[n], cnt));

    //FORALL(it, s) cout << it->FI << ' ' << it->SE << endl;
    
    FOR(i,1,m) {
        int u, v;
        cin >> u >> v;
        int realU = 0;
        while (u && SZ(s)) {
            set<II>::iterator it = s.begin();
            int sz = it->SE;
            int val = it->FI;
            if (v < val) break;
            s.erase(it);
            if (sz <= u) {
                realU += sz;
                u -= sz;
            }
            else {
                sz = sz - u;
                s.insert(II(val, sz));
                realU += u;
                break;
            }
        }
        //cout << realU << endl;
        if (realU) {
            set<II>::iterator it = s.lower_bound(II(v, 0));
            if (it != s.end()) {
                if (it->FI == v) {
                    int sz = it->SE;
                    s.erase(it);
                    s.insert(II(v, realU + sz));
                }
                else {
                    s.insert(II(v, realU));
                }
            }
            else {
                s.insert(II(v, realU));
            }
        }
        //FORALL(it, s) cout << it->FI << ' ' << it->SE << endl;
        cout << endl;
    }
    ll res = 0;
    FORALL(it, s) res += (ll) it->FI * it->SE;
    cout << res;
    return 0;
}

Measured memory_bytes: 5376
fn read<T: std::str::FromStr>() -> T {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).ok();
	s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().split_whitespace()
		.map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
	(0..n).map(|_| read_vec()).collect()
}

pub trait LexicalPermutation {
	/// Return `true` if the slice was permuted, `false` if it is already
	/// at the last ordered permutation.
	fn next_permutation(&mut self) -> bool;
}
impl<T> LexicalPermutation for [T] where T: Ord {
	/// Original author in Rust: Thomas Backman <serenity@exscape.org>
	fn next_permutation(&mut self) -> bool {
		// These cases only have 1 permutation each, so we can't do anything.
		if self.len() < 2 { return false; }

		// Step 1: Identify the longest, rightmost weakly decreasing part of the vector
		let mut i = self.len() - 1;
		while i > 0 && self[i-1] >= self[i] {
			i -= 1;
		}

		// If that is the entire vector, this is the last-ordered permutation.
		if i == 0 {
			return false;
		}

		// Step 2: Find the rightmost element larger than the pivot (i-1)
		let mut j = self.len() - 1;
		while j >= i && self[j] <= self[i-1]  {
			j -= 1;
		}

		// Step 3: Swap that element with the pivot
		self.swap(j, i-1);

		// Step 4: Reverse the (previously) weakly decreasing part
		self[i..].reverse();

		true
	}
}

fn main() {
	let (a, b) = {
		let tmp: Vec<usize> = read_vec();
		(tmp[0], tmp[1])
	};

	let b_min_price = b * 10;
	let	b_max_price = (b+1) * 10;

	for i in b_min_price..b_max_price {
		if ((i*100) * 8)/10000 == a {
			println!("{}", i);
			return;
		}
	}
	println!("-1");
}


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

 
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

const long long inf = 1e18;
const long long mod = 1e9+7;
vector<int> a;
long long dp[110][100010];

//dp[i][j]:i人まででj個分ける時の通り数
//dp[i][0] = 1
//dp[i][j] = dp[i-1][j]+dp[i-1][j-1]+...+dp[i-1][j-a[i-1]]
//i番目に0個、1個、...、a[i-1]個配る
//dp[i][j-1]を使って式変形
//dp[i][j] = dp[i][j-1]+dp[i-1][j]+dp[i-1][j-a[i]-1]
int main() {
    int N, K;
    cin >> N >> K;
    a.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i <= N; i++) {
        dp[i][0] = 1;
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < K; j++) {
            if (j-a[i] >= 0) {
                dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j-a[i]] + mod) % mod; //modを足しているのはマイナスにならないように
            } else {
                dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1]) % mod;
            }
        }
    }
    cout << dp[N][K] << endl;
    return 0;
}

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

using namespace std;

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

    deque<int> dq;
    for (int i = 1; i <= n; ++i) {
        int a;
        cin >> a;
        if ((n - i) % 2 == 0) {
            dq.push_front(a);
        } else {
            dq.push_back(a);
        }
    }

    for (auto x:dq) {
        cout << x << " ";
    }
    cout << endl;
    return 0;
}

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

int main(){
    int M, D;
    cin >> M >> D;

    int ans = 0;
    for(int d=1;d<=D;d++){
        int d1=d%10, d10=d/10;
        if(d1 >= 2 && d10 >= 2 && d1*d10 <= M) ans++;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 768
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
f = gets.split.map(&:to_i)

a.sort!

f.sort!
f.reverse!

l = -1
r = 10**12

while (r-l != 1) do
    mid = (r+l) / 2
    cnt = 0
    for i in 0...n
        x = a[i] - mid / f[i]
        cnt += x if x > 0
    end

    if cnt <= k
        r = mid
    else
        l = mid
    end
end

puts r


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

int main(){
    int n, s = 0;
    cin >> n;
    vector<int> v(n);
    rep(i, n){
        cin >> v.at(i);
    }
    bool flag = true;
    while(flag){
        flag = false;
        for(int i = n-1; i > 0; i--){
            if(v.at(i) < v.at(i-1)){
                swap(v.at(i), v.at(i-1));
                flag = true;
                s++;
            }
        }
    }
    repc(i, v.begin(), v.end()){
        cout << (i != v.begin() ? " " : "") << *i;
    }
    cout << endl << s << endl;
    return 0;
}


Measured memory_bytes: 3084
#include <stdio.h>
#define N 102
int G[N][N];
int main(){
    int n,i,j,u,n2,v;
    scanf("%d",&n);
    
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            G[i][j] = 0;
        }
    }
    
    for(i = 0; i < n; i++){
        scanf("%d %d",&u,&n2);
        for(j = 0; j < n2; j++){
            scanf("%d",&v);
            G[u-1][v-1] = 1;
        }
    }
    for(i = 0; i < n; i++){
      for(j = 0; j < n; j++){
        printf("%d",G[i][j]);
          if(j != n-1){
            printf(" ");
          }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int x = 0;
		int y = 0;

		int ans = 0;
		for (int i = 0; i < n; i++) {
			
			x = sc.nextInt();
			y = sc.nextInt();
			
			ans += y-x+1;
			
		}

		System.out.println(ans);

		sc.close();

	}
}

Measured memory_bytes: 25544
import sys

d = sys.stdin.readline()
while d:
    a,b,c,d,e,f = map(int,d.split())
    inv = 1/(a*e - b*d)
    iA = [[e,-b],[-d,a]]
    B = [c,f]
    sol = list()
    for i in range(2):
        tmp = 0
        for j in range(2):
            tmp += inv*iA[i][j] * B[j]
        sol.append(tmp)
    print("%.3f %.3f"%(sol[0],sol[1]))

    d = sys.stdin.readline()

Measured memory_bytes: 7648
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string.h>
#include <deque>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;



int main() {
	int n,a, b, c;
	cin >> n;
	REP(i, 0, n) {
		cin >> a >> b >> c;
		if (a*a == b*b + c*c || b*b == a*a + c*c || c*c == b*b + a*a) {
			cout << "YES" << endl;
		}
		else cout << "NO" << endl;
	}
	return 0;
}

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

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

// combination(n,r)
int combination(int n, int r){
	if(r == 0 || r == n)	return 1;
	else if(r == 1)	return n;
	return (combination(n - 1, r - 1) + combination(n - 1, r));
}

// gcd(a,b)
int gcd(int a,int b){
	return (b == 0) ? a : gcd(b, a % b);
}

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

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*a - *b);
}

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
	return temp;
}

void nongetpop(int *array,int *size){
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
}

int main(int argc, char const *argv[])
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a + b == 15)	puts("+");
	else if(a * b == 15)	puts("*");
	else puts("x");
	return 0;
}


Measured memory_bytes: 128
//it was hard to write
//so it should be hard to read
#include <bits/stdc++.h>
#define sz size
#define pb push_back
#define ll long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define last(x) (x).size() - 1
#define mp make_pair

using namespace std;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef double ld;

const int MAXN = 1e5 + 5;
const ll INF = 1e18 + 7;
const int inf = 1e9 + 7;
const double EPS = 1e-9;

string s;
string res;

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    cin >> s;
    for (int i = 0; i < s.sz(); i++) {
        if (s[i] == 'B') {
            if (res.empty()) continue;
            res.erase(res.begin() + res.sz() - 1);
        }
        else {
            res += s[i];
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
import sys
f = sys.stdin

from collections import deque
import operator

func = {'+':operator.add,'-':operator.sub,'*':operator.mul,'/':operator.truediv }

for line in f:
    stack = deque()
    for element in line.strip().split():
        if element in func:
            b = stack.pop()
            a = stack.pop()
            stack.append(func[element](a, b))
        else:
            stack.append(float(element))
    print('{:.6f}'.format(stack[0]))
        

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
int main(){
   ll a,b; cin>>a>>b;
   ll g=gcd(a,b);
   ll ans=a/g*b;
   cout<<ans<<endl;
   return 0;
}

   


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

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

// Self settings
// clang-format off
#define MAX_N 20
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int A[MAX_N], B[MAX_N], C[MAX_N];

int main(void)
{
  int N;
  cin >> N;
  REP(i, N)
  {
    int x;
    cin >> x;
    // 0-indexed
    A[i] = x - 1;
  }
  REP(i, N) cin >> B[i];
  REP(i, N - 1) cin >> C[i];

  int ans = 0;
  int prev = INT_MAX;
  for (int i = 0; i < N; i++) {
    ans += B[A[i]];
    if (A[i] - prev == 1) {
      ans += C[prev];
    }
    prev = A[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		for (int i = 1000; i <= 10000; i += 1000)
			if (n <= i) {
				ans = i - n;
				break;
			}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 35684
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define i_inf int(1e9)
#define i_half_inf int(1e5)
#define ll_inf ll(1e9)*ll(1e9)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int max_n = i_half_inf;
ll n, a[max_n];

void solve() {
    sort(a, a + n);
    ll dp[n];
    dp[0] = a[0];
    repone(i, n - 1) dp[i] = dp[i - 1] + a[i];
    ll target = a[n - 1], ans = 1;
    repr(i, n - 1) {
        if (dp[i] * 2 >= target) ans++;
        else {
            target = a[i + 1];
            if (dp[i] * 2 >= target) ans++;
            else break;
        }
    }
    cout << ans << endl;
}

int main() {
    cin >> n;
    rep(i, n) cin >> a[i];
    solve();
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;
vector<int> a, b, c, d;
int N, M, Q;

int dfs(vector<int> now) {
    int n = (int)now.size();
    if (n == N) {
        int ans = 0;
        for (int i = 0; i < Q; i++) {
            if (now[b[i] - 1] - now[a[i] - 1] == c[i]) {
                ans += d[i];
            }
        }
        return ans;
    } else {
        int ans = 0;
        if (n == 0) {
            for (int nxt = 1; nxt <= M; nxt++) {
                vector<int> next = now;
                next.push_back(nxt);
                chmax(ans, dfs(next));
            }
        } else {
            for (int nxt = now[n - 1]; nxt <= M; nxt++) {
                vector<int> next = now;
                next.push_back(nxt);
                chmax(ans, dfs(next));
            }
        }
        return ans;
    }
}

int main() {
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    for (int i = 0; i < Q; i++) {
        cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    }

    cout << dfs(vector<int>(0)) << endl;
}


Measured memory_bytes: 3604
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

alp = gc.uniq
ans = ALP - alp
puts ans.size > 0 ? ans.sort.first : 'None'


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

int main(){
        string s;
        cin>>s;
        int max_num_p=s.size()/2;
        int num_p_t=0;
        for(int i=0; i<s.size(); i++){
                if (s[i]=='p') num_p_t++;
        }
        int num_win=max_num_p-num_p_t;
        cout<<num_win;
        return 0;
}



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

int main() {
  string a,b;
  cin >> a >> b;
  if ( a=="H") {
    cout << b << '\n';
  } else {
    cout << ( b=="H" ? "D" : "H" ) << '\n';
  }
  return 0;
}

Measured memory_bytes: 3524
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
ll t=1000000000000;
int main(){
	int n;
	cin>>n;
	ll a[n],sum=0,sum1=0,sum2=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	ll ans=0;
	for(int i=0;i<n-1;i++){
		sum1=sum1+a[i];
		ans=sum-sum1*2;
		ans=abs(ans);
		if(t>ans){
			t=ans;
		}
	}
	cout<<t<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)3e5+5;
const int Q = 301;

void solve() {
	int h,w,n;
    cin>>h>>w>>n;
    h = max(h, w);
    cout<<(n + h - 1)/h;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        //cout<<"\n";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;

int main()
{
	ll n, m, a, b, ans = 0;
	multimap<ll, ll> job;
	multimap<ll, ll>::iterator pm;
	priority_queue<ll, vector<ll>> candidate;

	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		job.insert(make_pair(a, b));
	}

	pm = job.begin();
	for (int i = 1; i <= m; i++)
	{
		ll k = job.count(i);
		for (int j = 0; j < k; j++)
		{
			candidate.push(pm->second);
			pm++;
		}
		if (candidate.size() != 0)
		{
			ans += candidate.top();
			candidate.pop();
		}
	}
	cout << ans;
}

Measured memory_bytes: 7676
# -*- coding: utf-8 -*-
"""
Created on Thu Apr  4 14:15:23 2019

@author: fumito
"""

S = str(input())
S_list = [i for i in S]
list1 = []
for i in S_list:
    if i == 'A' or i == 'C' or i == 'G' or i == 'T':
        list1.append(0)
    else:
        list1.append(1)

list2 = []
count = 0    
for j,k in enumerate(list1): 
    if k == 0:
        count += 1
    if k == 1 or j == len(list1)-1:
        list2.append(count)
        count = 0
print(max(list2))

    

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

int main()
{
    std::string s;
    std::cin >> s;
    int l, r, ans = 0;
    l = 0, r = s.size() - 1;
    if (s.size() % 2 == 0)
    {
        while (r - l > 0)
        {
            if (s[l] != s[r]) { ans++; }
            l++, r--;
        }
    }
    else
    {
        while (r - l > 1)
        {
            if (s[l] != s[r]) { ans++; }
            l++, r--;
        }
    }

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

    return 0;
}

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

int hoge(int b, int n, int s) {
    if (n == 1)
        return (0 <= s && s <= 9 && b <= s)? 1 : 0;
    int sum = 0;
    for (int i = b; i <= 9; ++i)
        sum += hoge(i+1, n-1, s-i);
    return sum;
}

int main(void) {
    int n, s;
    while (cin >> n >> s && (n!=0 || s!=0)) {
        cout << hoge(0, n, s) << endl;
    }
    return 0;
}



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

int n, k, bad[10];

int ok(int n) {
	for(int i = n; i > 0; i /= 10)
		if(bad[i % 10])
			return 0;

	return 1;
}

int main() {
	scanf("%d%d", &n, &k);

	for(int i = 1; i <= k; i++) {
		int d; scanf("%d", &d);
		bad[d] = 1;
	}

	while(!ok(n)) n++;

	printf("%d\n", n);
	return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const ll MOD = 1000000007;

int N;
int x[100010];

int main() {
	cin >> N;
	rep(i, N) cin >> x[i];

	ll ret = 1;
	int num = 0;

	rep(i, N) {
		if (num * 2 + 1 <= x[i]) {
			++num;
		} else {
			ret = ret * (num + 1) % MOD;
		}
	}

	for (int i = 1; i <= num; ++i) {
		ret = ret * i % MOD;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 640
n=gets.to_i
m=gets.split.map do |n|
if n=="0"
puts 0
exit
end
n.to_i
end

result=1
for i in 0..n-1
    v=result
    result=m[i]*v

    if result>10**18
    result=-1
    break
    end
end
 
p result

Measured memory_bytes: 24160
n   = gets.to_i
ary = gets.split.map(&:to_i)

aryE = {-1 => 0}
aryO = {-1 => 0}

n.times do |i|
  temp = ary[i]
  if i % 2 == 0
    if aryE[temp] == nil
      aryE[temp] = 1
    else
      aryE[temp] += 1
    end
  else
    if aryO[temp] == nil
      aryO[temp] = 1
    else
      aryO[temp] += 1
    end
  end
end

aryE = aryE.sort_by{|a| a[1]}.reverse
aryO = aryO.sort_by{|a| a[1]}.reverse

if aryE[0][0] != aryO[0][0]
  puts n - aryE[0][1] - aryO[0][1]
else
  puts n - [aryE[1][1] + aryO[0][1], aryE[0][1] + aryO[1][1]].max
end

Measured memory_bytes: 20724
import sys
import bisect
input = sys.stdin.readline

def solve():
  s = int(input())
  if s <= 10**9:
    print("0 0 1 0 1",end =" ")
    print(s)
  else:
    print("0 0 1000000000 1",end=" ")
    c = (s+1000000000-1)//1000000000
    print(1000000000*c-s,end =" ")
    print(c)
    
solve()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<ll,pair<ll,char>>
#define sorted(a_1) sort(a_1.begin(),a_1.end())
#define rsorted(a_1) sort(a_1.rbegin(),a_1.rend())
#define t1(a_1) cout<<a_1<<endl;
#define t2(a_1) for(auto it_test : a_1) cout<<it_test<<" ";
#define MOD 1000000007

ll dp[1<<22];
ll topDown(vector<vector<int>>&arr, int n,int man, ll mask){
	ll ans = 0;
	if(man==n) return 1;
	if(dp[mask]>-1){ return dp[mask]%MOD;}
	for(int i=1;i<=n;i++){
		int k = mask & 1<<i;
		if(arr[man][i-1] && k==0){
			ll p = mask | 1<<i;
			ans += topDown(arr,n,man+1,p);
			ans%=MOD;
		}
	}  
	dp[mask] = ans;
	return ans;
}
// 2^21 =2 * 10^6
void solve(){
    int n;
    cin>>n;
    vector<vector<int>>arr(n+1,vector<int>(n+1));
    for(int i=0;i<n;i++){
    	for(int j=0;j<n;j++){
    		cin>>arr[i][j];
    	}
    }
    memset(dp,-1,sizeof(dp));
    ll ans = topDown(arr,n,0,1LL);
    t1(ans%MOD);
    // for(int i=0;i<n;i++){
    // 	for(int j=0;j<=2^n;j++){

    // 	}
    // }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    while(t--){
        solve();
    }

return 0;
}

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

S=[[] for _ in range(N)]
for _ in range(M):
    a,b=map(int,input().split())
    S[a-1].append(b-1)
    S[b-1].append(a-1)

L=[-1]*N
L[0]=0
tmp=[0]
while tmp:
    T0=tmp.pop(0)
    
    for j in S[T0]:
        if L[j]==-1:
            L[j]=T0
            tmp.append(j)

label=True
for j in L:
    if L==-1:
        label=False
if label:
    print('Yes')
    for j in L[1:]:
        print(j+1)
else:
    print('No')

Measured memory_bytes: 34340
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
 
using namespace std;
 
int main() {
  int n; cin >> n;
  vector<int> as(n, 0);
  for (auto& a : as) cin >> a;
  
  vector<int> dp(n, 0);
  dp[0] = 0;
  dp[1] = abs(as[1] - as[0]);
  for (int i = 2; i < n; i++) {
    dp[i] = min(dp[i - 1] + abs(as[i] - as[i - 1]), 
                dp[i - 2] + abs(as[i] - as[i - 2]));
  }
  cout << dp[n - 1] << endl;
}

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


def solve(N: int):
    count = 0

    for i in range(1, N + 1):
        if i % 2 != 0:
            count += 1

    print('{:0<12}'.format(count / N))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef vector<char> vc;
typedef vector<vector<char> > vvc;
typedef vector<double> vd;
typedef vector<vector<double> > vvd;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}

int main() {
    ll n, x;
    cin >> n >> x;
    ll ma = max(x, n - x);
    ll mi = min(x, n - x);
    ll ans = 0;
    ans += n;
    while (true) {
        ll cnt = ma / mi;
        if ( ma != mi * cnt ) {
            ans += mi*2 * cnt;
            ma -= mi * cnt;
            swap(ma, mi);
        } else {
            ans += mi * (cnt * 2 - 1);
            break;
        }
    }
    printf("%lld\n", ans);

    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

long long powmod(long long a,long long b){
    long long c=1;
    while(b>0){
        if(b&1) c=a*c%mod;
        a=a*a%mod;
        b>>=1;
    }
    return c;
}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll k,ans=0;
	cin >> k;
	REP(i,1,k){
		REP(j,1,k){
			REP(l,1,k) ans+=gcd(i,gcd(j,l));
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
input()
a=list(map(int,input().split()))
b=sorted(a)
c=0
for i in range(len(a)):
 x=a.index(b[i])
 j=0
 while x>i:
  j+=1
  y=a.index(b[x])
  c+=a[y]
  a[x],a[y]=a[y],a[x]
  x=y
 c+=min(b[i]*j,b[i]*2+b[0]*(j+2))
print(c)


Measured memory_bytes: 5620
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cfloat>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong C[55][55];
void comb_table(int N){
    for(int i=0;i<=N;++i){
        for(int j=0;j<=i;++j){
            if(j==0 || j==i){
                C[i][j]=1LL;
            }else{
                C[i][j]=(C[i-1][j-1]+C[i-1][j]);
            }
        }
    }
}

llong n, a, b;
llong v[55];
llong sum[55];

int main() {
    comb_table(50);
    
    cin >> n >> a >> b;
    for (llong i = 1; i <= n; i++) {
        cin >> v[i];
    }
    sort(v + 1, v + n + 1, greater<>());

    for (llong i = 1; i <= n; i++) {
        sum[i] = sum[i - 1] + v[i];
    }

    __float128 maxv = 0;
    for (llong i = a; i <= b; i++) {
        __float128 avg = (sum[i]) / ((__float128)i);
        maxv = max(avg, maxv);
    }
    
    llong ans = 0 , last = -1;
    for (llong i = a; i <= b; i++) {
        __float128 avg = (__float128)sum[i] / (__float128)i;

        if (maxv == avg) {
            llong t = v[i];
            llong N = 0;
            llong K = 0;
            assert(last == -1 || last == v[i]);
            for (llong j = 1; j <= n; j++) {
                if (v[j] == t) N++;
            }
            for (llong j = i; j > 0; j--) {
                if (v[j] == t) K++;
            }

            ans += C[N][K];
        }
    }

    printf("%.*lf\n", DBL_DIG, (double)maxv);
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
// Why am I so dumb? :c
#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)2e5 + 5;

int arr[MAXN];

ll ans;

int n;

void solve() {
	scanf("%d", &n);

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

	if (arr[1] != 0) {
		printf("-1\n");
		return;
	}

	int cur = 0;
	
	for (int i = n; i > 0; --i) {
		if (arr[i] < cur) {
			printf("-1\n");
			return;
		}

		if (arr[i] != cur) {
			ans += arr[i];
			cur = arr[i];
		}

		--cur;
	}

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

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 1024
import heapq

K = int(input())
D = [9999]*K
D[1] = 1
H = [(1,1)]
while len(H) != 0:
    c,h = heapq.heappop(H)
    if D[(h*10)%K] > c:
        D[(h*10)%K] = c
        H.append((c,(h*10)%K))
    if D[(h+1)%K] > c + 1:
        D[(h+1)%K] = c + 1
        H.append((c+1,(h+1)%K))

print(D[0])

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

// D - RGB Triplets
int main() {
    int N;
    string S;
    cin >> N >> S;

    if (N < 3) {
        cout << 0;
        return 0;
    }

    int r = 0, g = 0, b = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R') r++;
        if (S[i] == 'G') g++;
        if (S[i] == 'B') b++;
    }

    long long all = (long long)r * g * b;

    // int minus = 0;
    for (int i = 0; i < N - 2; i++) {
        for (int j = i + 1; j < N - 1; j++) {
            if (j + (j - i) >= N) break;
            if (S[i] != S[j] && S[i] != S[j + (j - i)] && S[j + (j - i)] != S[j]) {
                // cout << "i:" << i << S[i] << ", j:" << j << S[j] << ", k:" << j + (j - i) << S[j + (j - i)] << endl;
                // minus++;
                all--;
            }
        }
    }

    cout << all;
    // cout << (long long)(r * g * b) - minus;
}


Measured memory_bytes: 3588
#include<iostream>
using namespace std;
struct Node{int parent,left,right;};
#define NIL -1
struct Node T[26];
int n,p,l,r,s;
void Preorder(int x){
    cout<<" "<<x;
    if(T[x].left!=NIL) Preorder(T[x].left);
    if(T[x].right!=NIL) Preorder(T[x].right);
}
void Inorder(int x){
    if(x!=NIL){
    Inorder(T[x].left);
    cout<<" "<<x;
    Inorder(T[x].right);  
    }
}
void Postorder(int x){
    if(x!=NIL){
        Postorder(T[x].left);
        Postorder(T[x].right);
        cout<<" "<<x;
    }
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++) T[i].parent=T[i].left=T[i].right=NIL;
    for(int i=0;i<n;i++){
        cin>>p>>l>>r;
        if(l!=NIL){T[p].left=l; T[l].parent=p;}
        if(r!=NIL){T[p].right=r; T[r].parent=p;}
    }
    for(int i=0;i<n;i++){
        if(T[i].parent==NIL) s=i;
    }
    cout<<"Preorder"<<endl;
    Preorder(s); cout<<endl;
    cout<<"Inorder"<<endl;
    Inorder(s); cout<<endl;
    cout<<"Postorder"<<endl;
    Postorder(s); cout<<endl;
    return 0;
}


Measured memory_bytes: 3072
#include<stdio.h>

int main(){
  int a,b,c,x;

  scanf("%d %d %d",&a, &b, &c);

  if ( a > b ) {
    x = a;
    a = b;
    b = x;
  }

  if ( b > c ) {
    x = b;
    b = c;
    c = x;
  }

  if ( a > b ) {
    x = a;
    a = b;
    b = x;
  }

  printf("%d %d %d\n", a, b, c);

  return 0;
}

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

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector<long long> A(N+1,0),B(M+1,0);
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    A[i] += A[i-1];
  }
  for (int i = 1; i <= M; i++) {
    cin >> B[i];
    B[i] += B[i-1];
  }
  int j = M;
  int ans = 0;
  for (int i = 0; i < N+1; i++) {
    if (A[i] > K) break;
    while (A[i]+B[j] > K && j > 0) j--;
    ans = max(ans, i+j);
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long LL;

const int N = 1e5 + 10;
int x[N];

int main() {
    int n, a, b;
    scanf("%d%d%d", &n, &a, &b);
    for (int i = 0; i < n; i++) scanf("%d", x + i);
    LL ans = 0;
    for (int i = 1; i < n; i++) {
        ans += min(1ll * (x[i] - x[i-1]) * a, (LL)b);
    }
    printf("%lld\n", ans);
    return 0;
}


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

void test_case(){
    
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL);
    int aa, bb, m;
    cin >> aa >> bb >> m;
    int a[aa], b[bb];
    
    rng(i, 0, aa)
        cin >> a[i];
    rng(i, 0, bb)
        cin >> b[i];
    
    int x, y, c;
    int res = INT_MAX;
    rng(i, 0, m){
        cin >> x >> y >> c;
        x--; y--;
        
        res = min( res, a[x] + b[y] - c);
    }
    x = a[0];
    rng(i, 0, aa)
        x = min(x,a[i]);
    y = b[0];
    rng(i, 0, bb)
        y = min(y, b[i]);
        
    res = min(res, x+y);
    cout<<res<<endl;
    
	return 0;
}






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

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

	int *a = new int[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = n - 1; i >= 0; i--) {
		cout << a[i];
		if (i > 0)
			cout << " ";
	}
	cout << endl;
}

Measured memory_bytes: 1188
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int x = sc.nextInt();
		
		if(a < b) {
			System.out.println((int) Math.ceil((double) x / 1000) * a); 
		}else if(a < b * 2) {
			if(x % 1000 <= 500 && x % 1000 > 0) {
				System.out.println((int) x / 1000 * a + b);
			}else {
				System.out.println((int) Math.ceil((double) x / 1000) * a); 
			}
		}else {
			System.out.println((int) Math.ceil((double) x / 500) * b); 
		}
	}
}


Measured memory_bytes: 26108
#include <stdio.h>

int main(void)
{
	int a,b,c;
	int temp;
	
	scanf("%d %d %d", &a,&b,&c);
	
	while(0<=a,b,c && 1000>=a,b,c){
	
		if(a>b){
			temp=b;
			b=a;
			a=temp;
		}
		
		if(a>c){
			temp=c;
			c=a;
			a=temp;
		}
		
		if(b>c){
			temp=c;
			c=b;
			b=temp;
		}
			
			
			break;
	
		}
	
	printf("%d %d %d\n",a,b,c);
	
	
	
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<pair<long long,long long>> xy(n);

  for (int i = 0; i < n; i++)
  {
    long long x,y;
    cin >> x >> y;
    xy[i]=make_pair(x,y);
  }
  sort(xy.begin(),xy.end());

  map<pair<long long,long long>,int> mp;

  for (int i = 0; i < n-1; i++)
  {
    for (int j = 1; j < n-i; j++)
    {
      long long dx = xy[i+j].first-xy[i].first;
      long long dy = xy[i+j].second-xy[i].second;
      mp[make_pair(dx,dy)]++;
    }
  }

  int maxd = 0;
  for(auto s:mp){
    maxd=max(maxd,s.second);
  }
  
  cout << n-maxd << endl;

}

Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
  int N;
  int max = 0;
  scanf("%d", &N);
  int C[N], V[N];
  for (int n = 0; n < N; ++n) scanf("%d", &V[n]);
  for (int n = 0; n < N; ++n) scanf("%d", &C[n]);
  for (int n = 0; n < N; ++n) max += (V[n] - C[n] >= 0) * (V[n] - C[n]);
  printf("%d\n", max);
  return 0;
}


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

typedef long long ll;
struct Bun{
  ll a,b;
  Bun(ll a,ll b):a(a),b(b){
    init();
  }
  void init(){
    ll x = abs(__gcd(a,b));
    a/=x; b/=x;    
  }
  Bun operator+(Bun y){
    Bun x = *this;
    ll r = x.b*y.b/__gcd(x.b,y.b);
    x.a*=r/x.b;
    y.a*=r/y.b;
    Bun res = Bun( x.a + y.a , r );
    return res;
  }
  Bun operator-(Bun y){
    y.a*=-1;
    return (*this)+y;
  }
};

int main(){
  string s;
  while( cin >> s ){
    if( s == "#" ) break;
    int cnt = (int)s.size()-1;
    Bun p = Bun(0,1);
    int n=0;

    while( 0 < cnt ){
      ll ni=1;
      for(int i=0;i<n;i++) ni*=2;
      if( 2<cnt && s.substr(cnt-3,4) == "west" ){
        if( cnt == (int)s.size()-1 ) p = Bun(90,1);
        else p = p+Bun(90,ni);        
        cnt-=4;
        n++;
      } else {
        if( cnt == (int)s.size()-1 ) p = Bun(0,1);
        else p = p-Bun(90,ni);
        cnt-=5;
        n++;             
      }
    }
    if( p.b == 1 ){
      cout << p.a << endl; 
    } else {
      cout << p.a << "/" << p.b << endl;
    }

  }
  
}

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

using namespace std;

typedef complex<double> P;

P reflection(P a,P b,P c)
{
    b-=a;c-=a;
    return a+2.0*b*real(c/b)-c;
}

int main()
{
    double x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;

    int q;
    cin>>q;
    while(q--)
    {
        double x,y;
        cin>>x>>y;
        P p=reflection(P(x1,y1),P(x2,y2),P(x,y));
        cout<<fixed<<setprecision(10)<<p.real()<<" "<<p.imag()<<endl;
    }

    return 0;
}




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

int main(){

  int N,K;
  cin >> N >> K;

  //std::vector<int> v(N);

  int sum = 0;
  for(int i=0;i<N;++i){
    int shincho;
    cin >> shincho;
    if (shincho >= K) sum++;
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    ll X;
    cin >> X;
    ll A,B;
  	A=-1;
    for(ll i=1; i<=100000; i++){
        ll a=i*i*i*i*i;
        ll b=a-X;
      	bool c;
        if(b<0){
            b = -b;
            c=true;
        }else{
            c=false;
        }
        for(ll j=0; j<=10000; j++){
            ll d=j*j*j*j*j;
            if(d==b){
                A=i;
                if(c) B=-j;
                else B=j;
                break;
            }
        }
      	if(A!=-1) break;
    }
    cout << A << " " << B << endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;

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

    int n;    
    cin >> n;
    vi a(n), b(n), c(n);
    vector<vi> dp(n, vi(3));
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i] >> c[i];
    }
    dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0];
    for (int i = 1; i < n; ++i) {
        dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
    }
    cout << max(dp.back()[0], max(dp.back()[1], dp.back()[2])) << '\n';

    return 0;
}

Measured memory_bytes: 6912