akhauriyash/Code-Regression huggingface dataset:
import collections

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

l = [0] * (10**5 + 1)
# print(l)
# print(len(l))
c = collections.Counter(A)
# print(c)
for key in c:
    l[key] = c[key]
# print(l)
ans = 0
for item in c:
    ans += item * c[item]

# print(ans)  # i=0

for i in range(Q):
    if B[i] in c:
        # print(c)
        ans = ans - B[i] * c[B[i]] + C[i] * c[B[i]]
        c[C[i]] += c[B[i]]
        c.pop(B[i])
    print(ans)


Measured memory_bytes: 28312
function main()
	lines=readlines()
	H,W=map(x->parse(Int,x),split(shift!(lines)))
	S=Array{Int}(H,W)
	for i=1:H
		s=shift!(lines)
		for j=1:W
			S[i,j]=s[j]=='.'
		end
	end
	dp1=copy(S)
	dp2=copy(S)
	dp3=copy(S)
	dp4=copy(S)
	for x=2:H
		dp1[x,:].*=dp1[x-1,:]+1
	end
	for x=H-1:-1:1
		dp2[x,:].*=dp2[x+1,:]+1
	end
	for y=2:W
		dp3[:,y].*=dp3[:,y-1]+1
	end
	for y=W-1:-1:1
		dp4[:,y].*=dp4[:,y+1]+1
	end
	println(maximum(dp1+dp2+dp3+dp4)-3)
end
main()


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

int main() {
int X;
  cin >> X;
  int suuji1, suuji2;
  int count = 0;
  for(int i = 0; i < 1000; i++){
    if(count != 0){
      break;
    }
    else {
  		for(int j = 0; j < 1000; j++){
 	   		suuji1 = pow(i,5) + pow(j,5);
   	   		suuji2 = pow(i,5) - pow(j,5);
   	   		if(suuji1 == X){
            	cout << i << " " << -j << endl;
        		count++;
            }
          else if(suuji2 == X){
            	cout << i << " " << j << endl;
            	count++;
      		}
        }
    }
  }
}


Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MAX = 700000;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
signed main(void){
    int x,y; cin>>x>>y;
    COMinit();
    if((x+y)%3 != 0) {cout<<0<<endl; return 0;}
    int m = (x+y)/3;
    //cout<<m<<endl;
    int ans = 0;
    for(int i=0;i<=m;i++){
        int r = i, l = m - i;
        //cout<<r<<' '<<l<<endl;
        if( (x == (2*l + r)) && (y == (2*r + l))){
            //cout<<r<<' '<<l<<endl;
            //cout<<"*"<<endl;
            ans += COM(m, l);
            ans %= MOD;
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;
using ll = long long;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()

#define READ(x) (cin >> (x))

#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N, M;
  cin >> N >> M;
  
  vector<int> A(M);
  for (size_t i = 0; i < M; ++i) {
     READ(A[i]);
  }
  
  // main procedure
  int sum = accumulate(ALL(A), 0);

  int d = N - sum;
  int ans = (d >= 0 ? d : -1);

  // output
  WRITE_N(ans);
  
  return 0;
}


Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string s1,s2,s3;
    cin >> s1 >> s2 >> s3;
    cout << (char)toupper(s1[0]) << (char)toupper(s2[0]) << (char)toupper(s3[0]) << endl;
    return 0;
}


Measured memory_bytes: 3596
def collatz(n):
    if n % 2 == 0:
        return int(n/2)
    else:
        return int(3*n+1)

s = int(input())
a = [s]
i = 1
while True:
    n = collatz(a[i-1])
    try:
        index = a.index(n)
        print(len(a)+1)
        break
    except ValueError:
        a.append(n)
        i += 1

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

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

constexpr int INF = INT_MAX;

void chmax(ll &a, ll b){
    a = max(a, b);
}

ll dp[2005][4005][2];

int main(){
    int n;
    cin >> n;
    vector<P> ls;
    vector<int> id(n), r(n), a(n), w(n), t(n);
    for(int i=0;i<n;i++){
        cin >> r[i] >> a[i] >> w[i] >> t[i];
        ls.push_back(P(r[i]+t[i], i));
    }
    sort(ls.rbegin(), ls.rend());
    for(int i=0;i<n;i++) id[i] = ls[i].second;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=4000;j++){
            dp[i][j][0] = -INF;
            dp[i][j][1] = -INF;
        }
    }
    dp[0][4000][0] = 0;
    for(int i=0;i<n;i++){
        for(int j=4000;j>0;j--){
            for(int k=0;k<2;k++){
                if(dp[i][j][k] == -INF) continue;
                if(j <= r[id[i]]) continue;
                if(k==0){
                    chmax(dp[i][min(j-r[id[i]],t[id[i]])][1], dp[i][j][k] + a[id[i]]);
                }
                else{
                    chmax(dp[i][j-r[id[i]]][1], dp[i][j][k] + w[id[i]]);
                }
            }
        }
        for(int j=0;j<=4000;j++){
            dp[i+1][j][0] = max(dp[i][j][0], dp[i][j][1]);
        }
    }
    ll ans = 0;
    for(int i=0;i<=4000;i++){
        ans = max({ans, dp[n][i][0], dp[n][i][1]});
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 128412
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	int k;
	cin >> k;
	string s;
	cin >> s;
	if(s.size() <= k)
		cout << s;
	else
		cout << s.substr(0, k) + "...";
}


Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<int> b(n);
  bool ok = true;
  int maxi = 1;
  for(int i = 0; i < n; i++) {
    cin >> b[i];
    if(b[i] > i + 1){
      ok = false;
    }
    maxi = max(maxi, b[i]);
  }
  if(!ok){
    cout << -1 << '\n';
    return 0;
  }
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    for(int j = n - 1 - i; j >= 0; j--){
      if(b[j] == j + 1) {
        a[i] = j + 1;
        b.erase(b.begin() + j);
        break;
      }
    }
  }
  reverse(a.begin(), a.end());
  for(int i = 0; i < n; i++){
    cout << a[i] << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
a = list(input())
ans= []

for i in range(len(a)-2):
    X = a[i]
    Y = a[i + 1]
    Z = a[i + 2]
    aa = X + Y + Z
    ee = abs(753 - int(aa))
    ans.append(ee)

    
print(min(ans))

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

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


// std::vector Declaration
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
   return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// std::vector Initialization
template<typename T>
void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U>
void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
   os << "[";
   bool a = 1;
   for (auto e : v ) {
      os << (a ? "" : " "); 
      os << e;
      a = 0;
   }
   os << "]";
   return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
   os << "(" << p.first << " " << p.second << ")";
   return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
   os << "{";
   bool a = 1;
   for (auto e : st) {
      os << (a ? "" : " ");
      os << e;
      a = 0;
   }
   os << "}";
   return os;
}

// std::multiset Debug
template<typename T>
ostream& operator<<(ostream& os, const multiset<T>& st) {
   os << "{";
   bool a = 1;
   for (auto e : st) {
      os << (a ? "" : " ");
      os << e;
      a = 0;
   }
   os << "}";
   return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
   os << "{";
   bool a = 1;
   for (auto e : mp) {
      os << (a ? "" : " ");
      os << e.first << ":" << e.second;
      a = 0;
   }
   os << "}";
   return os;
}

// std::tuple Debug
template<int N, class Tuple>
void out(ostream& os, const Tuple& t){}
template<int N, class Tuple, class H, class ...Ts>
void out(ostream& os, const Tuple& t) {
   if (N) os << " ";
   os << get<N>(t);
   out<N+1,Tuple,Ts...>(os, t);
}
template<class ...Ts>
ostream& operator<<(ostream& os, const tuple<Ts...>& t) {
   os << "(";
   out<0,tuple<Ts...>,Ts...>(os, t);
   os << ")";
   return os;
}

// Debug
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl


struct edge { int to, cost; };
ostream& operator<<(ostream& os, const edge& e) {
   os << "(" << e.to << ", " << e.cost << ")";
   return os;
}

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

int main()
{
   int x, a; cin >> x >> a;
   if (x < a) {
      cout << 0 << endl;
   } else {
      cout << 10 << endl;
   }

   return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

int main() {
  int n, k;
  cin >> n >> k;
  p(n - k + 1);
}

Measured memory_bytes: 256
// Code by Nguyen Huu Lam
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long LL;

#define y0 Sword_Art_Online
#define y1 Your_lie_in_April
#define yn Darling_in_the_Franxx
#define tm Plastic_Memories
#define lr Charlotte
#define norm Weathering_with_you
#define left Violet_Evergarden
#define have Date_a_live
#define ends Your_name
#define prev Five_centimeters_per_second
#define hash Slient_voice

#define ordered_set tree<LL, null_type, less<LL>, rb_tree_tag, tree_order_statistics_node_update>
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

LL Rand(LL l, LL h){
    return uniform_int_distribution<LL>(l, h)(rng);
}

template <typename T> void read(T &t){
    t = 0; char ch = getchar(); int f = 1;
    while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
    do { (t *= 10) += ch - '0'; ch = getchar(); } while (isdigit(ch)); t *= f;
}

const LL MaxN = 1 + 1e5;

LL n, a[2][MaxN], kq, d[MaxN];
vector<LL> tmp;

void findPos(LL cnt, LL arr, LL&res){
    if(cnt == n){
        kq++;
        LL kt = 1;
        for(int i = 0 ; i < n ; ++i)
        if(a[arr][i] != tmp[i]){
            kt = 0;
            break;
        }
        if(kt) res = kq;
        return;
    }
    for(int i = 1 ; i <= n ; ++i)
    if(!d[i]){
        if(res != -1) return;
        d[i] = 1;
        tmp.push_back(i);
        findPos(cnt + 1, arr, res);
        tmp.pop_back();
        d[i] = 0;
    }
}

void InOut(){
    #define TASK "ABC"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
}

int main(){
    #ifdef LOCAL
        InOut();
        auto st = chrono::high_resolution_clock::now();
    #endif

    cin >> n;
    for(int i = 0 ; i < n ; ++i) cin >> a[0][i];
    for(int i = 0 ; i < n ; ++i) cin >> a[1][i];
    LL fir = -1, sec = -1;
    kq = 0;
    findPos(0, 0, fir);
    kq = 0;
    findPos(0, 1, sec);
    cout << abs(fir - sec) << endl;

    #ifdef LOCAL
        auto ed = chrono::high_resolution_clock::now();
        auto diff = ed - st;
        cerr << chrono::duration <double, milli> (diff).count() << " ms" << endl;
    #endif

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n;
	double x[8], y[8];
	int ord[8];

	cin >> n;
	rep(i, n)cin >> x[i] >> y[i];

	rep(i, n)ord[i] = i;
	double sum = 0;

	do {
		rep(i,n-1) {
			sum += sqrt((x[ord[i]] - x[ord[i + 1]]) * (x[ord[i]] - x[ord[i + 1]]) + (y[ord[i]] - y[ord[i + 1]]) * (y[ord[i]] - y[ord[i + 1]]));
		}
	}while(next_permutation(ord, ord + n));

	int z = 1;
	rep(i, n)z *= i + 1;
	printf("%.10f\n", sum / z);


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	ll n;
	cin >> n;

	V<ll> div1, divn;
	rep1(i, sqrt(n)) {
		if ((n - 1) % i == 0) {
			if (i != 1)div1.push_back(i);
			if (i * i != n - 1)div1.push_back((n - 1) / i);
		}
		if (n % i == 0) {
			if (i != 1)divn.push_back(i);
			if (i * i != n)divn.push_back(n / i);
		}
	}

	sort(all(div1));
	sort(all(divn));

	ll cnt = div1.size();
	for (auto x : divn) {
		ll nn = n;
		while (nn % x == 0)nn /= x;
		if (nn % x == 1)cnt++;
	}

	cout << cnt << endl;

}

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

int main() {

  int h, w;
  cin >> h >> w;

  for(int i = 0; i < w+2; i++){
    cout << '#';
  }
  cout << endl;

  string s;
  for(int i = 0; i < h; i++){
      
      cin >> s;
      cout << '#' << s << '#' << endl;

  }
  
  for(int i = 0; i < w+2; i++){
    cout << '#';
  }
  cout << endl;
  

}



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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	int N;
	cin >> N;
	vector<int>v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	bool ok = true;
	v[0]--;
	for (int i = 1; i < N; i++) {
		if (v[i] > v[i - 1]) {
			v[i]--;
		}
		if (v[i] < v[i - 1]) {
			ok = false;
			break;
		}
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 640
N,A,B = map(int,input().split())
if (B-A)%2 == 0:
    print((B-A)//2)
else:
    ans1 = B-1
    ans2 = A+(B-A-1)//2
    ans3 = (N-A)
    sita = (N-B)+1
    ans4 = sita+(N-(A+sita))//2
    print(min(ans1,ans2,ans3,ans4))

Measured memory_bytes: 38256
_,M,*A=`dd`.split.map &:to_i
*c=(*b=(*a=[z=0]*(2*M+1)))
A.each_cons(2){|l,r|
	l>r&&r+=M
	z+=r-l
	a[l+1]+=l
	a[r+1]-=l
	b[l+1]+=1
	b[r+1]-=1
}
1.upto(2*M){|i|
	a[i]+=a[i-1]
	b[i]+=b[i-1]
	c[i]=a[i]-b[i]*(i-1)
}
p z+A.map{|i|c[i]+c[i+M]}.min

Measured memory_bytes: 16012
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }
#define int long long

const int MOD = 1000000007;
//繰り返し二乗
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M);
}


const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
}
}

signed main() {
    ll n,a,b; cin>>n>>a>>b;
    init();
    ll ans=RepeatSquaring(2,n,MOD)-1;ans%=MOD;

    ll B=1;
    rep(i,b){
        B*=(n-i)*inv[i+1]%MOD;
        B=(B+MOD)%MOD;
    }
    ll A=1;
    rep(i,a){
        A*=(n-i)*inv[i+1]%MOD;
        A=(A+MOD)%MOD;
    }
    debug(A);
 
 
    debug(B)
    cout<<(ans-A-B+MOD*2)%MOD<<endl;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll,ll>;
using vpl = vector<pll>;
using vb = vector<bool>;
using vs = vector<string>;

const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define has(c,i) (c.find() != end(c))
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)

#define DBG 1
#define TR(X) ({ if(DBG) cerr << "TR: " << (#X) << " = " << (X) << endl; })

template<class T, class U>
ostream& operator<<(ostream& os, pair<T,U> obj){
	os << "(" << obj.xx << ", " << obj.yy << ")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> obj){
	os << "[";
	FOR(i,0,sz(obj)-1){
		os << obj[i] << ", ";
	}
	os << obj[sz(obj)-1] << "]";
	return os;
}


int main(void){
	cin.sync_with_stdio(false);
	cin.tie(NULL);

	ll N;
	string s;
	cin >> N >> s;

	FOR(i,0,sz(s)){
		s[i] -= 'A';
	}

	FOR(i,0,sz(s)){
		s[i] += N;
		s[i] %= 26;
	}
	FOR(i,0,sz(s)){
		s[i] += 'A';
	}
	cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main(void){
    char b[2];
    cin >> b;
    if (b[0] == 'A') cout << 'T' << endl;
    if (b[0] == 'T') cout << 'A' << endl;
    if (b[0] == 'G') cout << 'C' << endl;
    if (b[0] == 'C') cout << 'G' << endl;
}


Measured memory_bytes: 256
from collections import Counter
N = int(input())

def prime_factorization(n):
    table = []
    for x in range(2, int(n ** 0.5) + 1):
        while n % x == 0:
            table.append(x)
            n //= x
    if n > 1:
        table.append(n)
    return table


T = prime_factorization(N)
C = Counter(T)

ans = 0
for v in C.values():
    nx = 1
    while v >= nx:
        v -= nx
        ans += 1
        nx += 1

print(ans)


Measured memory_bytes: 9724
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,c,t,temp,x,y;
string str;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int k;
	cin>>n>>k;
	ll sum=0;
	vll v(n);
	read(v);
	ll mx=0;
	for(int i=0;i<k;i++)
	{
	    sum+=v[i];
	}
	mx=sum;
	for(int i=k;i<n;i++)
	{
	  sum+=(v[i]-v[i-k]);
	  mx=max(mx,sum);
	}
	cout<<fixed<<setprecision(6)<<(float)k/2+(float)mx/2;
	
	
	
	
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define SORT(i) sort((i).begin(), (i).end())
#define INF 2000000000
constexpr ll mod = 1e9 + 7;
 
int main(){
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << "\n";

    return 0;
}

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

int main() {
  char a, b;
  cin >> a >> b;
  string s, t;
  s = string(b - '0', a);
  t = string(a - '0', b);
  if (s <= t) {
    cout << s << endl;
  } else {
    cout << t << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#define ll long long 
using namespace std;
ll a, b, k;
int main()
{
	int t = 1;
	cin >> a >> b >> k;
	while (k--)
	{
		if (t == 1)
		{
			a = a / 2;
			b = b + a;
			t = 0;
		}
		else
		{
			b = b / 2;
			a = a + b;
			t = 1;
		}
	}
	cout << a <<' '<< b;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<vector<pair<int, int> > > vvp;
typedef vector<pair<int, int> > vp;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<vector<ll> > vvl;
typedef vector<ll> vl;
typedef vector<vector<bool> > vvb;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define yn(f) (f?"yes":"no")
#define YN(f) (f?"YES":"NO")
#define Yn(f) (f?"Yes":"No")
#define puts(s) cout<<(s)<<endl
#define inf (1000000007)
#define nil -1
class disjoint_set {
public:
	vi p, rank;
	disjoint_set(int size) {
		p.resize(size, 0);
		rank.resize(size, 0);
		for (int i = 0; i < size; i++)makeSet(i);
	}
	void makeSet(int x) {
		p[x] = x;
		rank[x] = 0;
	}
	bool same(int x, int y) {
		return findSet(x) == findSet(y);
	}
	void unite(int x, int y) {
		link(findSet(x), findSet(y));
	}
	void link(int x, int y) {
		if (rank[x] < rank[y]) {
			p[x] = y;
		}
		else {
			p[y] = x;
			if (rank[x] == rank[y]) {
				rank[x]++;
			}
		}
	}
	int findSet(int x) {
		if (x != p[x]) {
			p[x] = findSet(p[x]);
		}
		return p[x];
	}
};


ll gcd(ll a,ll b) {
	return a % b == 0 ? b : gcd(b,a%b);
}
ll lcs(ll a,ll b) {
	return a*b/gcd(a,b);
}
int main() {
	double n;
	cin >> n;
	vector<double> A(n);
	rep(i, 0, n)cin >> A[i];
	double sk = A[0];
	rep(i, 1, n) {
		sk = lcs(A[i],sk);
	}

	double num = 0;
	rep(i, 0, n) {
		num += sk / A[i];
	}
	puts((sk)/num);

}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define LP(i,N) for(int i=0;i<N;i++)
#define MAX 100
int H,W;
char map[MAX+1][MAX+1];
int dx[]={ 0, 1, 0,-1};
int dy[]={-1, 0, 1, 0};
void dfs(int h,int w,char fruit){
	if(map[h][w]=='0')return ;
	map[h][w]='0';
	LP(i,4){
		if(h+dy[i]<0||w+dx[i]<0||h+dy[i]>=H||w+dx[i]>=W||fruit!=map[h+dy[i]][w+dx[i]])continue;
		dfs(h+dy[i],w+dx[i],fruit);
	}
	return ;
}

int
main(){
	while(cin>>H>>W&&(H||W)){
		int count=0;
		LP(i,H){
			LP(j,W)cin>>map[i][j];
		}
		LP(i,H){
			LP(j,W){
				if(map[i][j]!='0'){
					count++;
					dfs(i,j,map[i][j]);
				}
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
int H,W,A,B;
int main(){
	cin>>H>>W>>A>>B;
	for (int i=1;i<=H;i++){
		for (int j=1;j<=W;j++)
			putchar(((i<=B)^(j<=A))+'0');
		putchar('\n');
	}
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

signed main(){
	IO_STREAM;
	int X;
	cin>>X;
	if(X==2){
		cout<<X<<endl;
		return 0;
	}
	while(1){
		int ng=0;
		if(X%2){
			for(int i=2;i*i<=X;i++){
				if(X%i==0){
					ng=1;
					break;
				}
			}
			if(ng==0){
				break;
			}
		}
		X++;
	}
	cout<<X<<endl;
	return 0;
}


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

double relative(double ax,double ay,double bx,double by){
    return ax*by-ay*bx;
}

int main(void){
    double x1, y1, x2, y2, x3, y3, xp, yp;
    while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)!=EOF){
        double r1=relative(x1-x3, y1-y3, xp-x1, yp-y1);
        double r2=relative(x2-x1, y2-y1, xp-x2, yp-y2);
        double r3=relative(x3-x2, y3-y2, xp-x3, yp-y3);
        if((r1<0&&r2<0&&r3<0) || (r1>0&&r2>0&&r3>0)) cout << "YES" <<"\n";
        else cout << "NO" << "\n";
    }
}



Measured memory_bytes: 3236
#include<bits/stdc++.h>
#define int long long int
#define ull unsigned long long int
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD 1000000007
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define precise(i) cout<<fixed<<setprecision(i)
using namespace std;
const double PI = atan(1.0)*4;
const int64_t INF=100000000000000003;
const int32_t LOG=21;
const int BIG=pow(2,20);
const int N=100005; 
 vector<pii> v;
 int n,time1;
 int dp[5005][5005];      
 int solve(int tot_time,int ind)
 {
       int x=ind;
       if(x==n)return 0;
       if(tot_time>=time1)return 0;
       int i=ind;
       int j=tot_time;
       if(dp[i][j]!=-1)return dp[i][j];
       dp[i][j]=max(v[i].s+solve(tot_time+v[i].f,i+1),solve(tot_time,i+1));
       return dp[i][j];
 } 
 int32_t main(){
         getFaster;
         cin>>n>>time1;
         rep(i,0,n)
         {
           int a,b;
           cin>>a>>b;
           v.push_back({a,b});
         }
         sort(v.begin(),v.end());
         rep(i,0,5005)rep(j,0,5005)dp[i][j]=-1;
         cout<<solve(0,0)<<endl;;
         return 0;
}

Measured memory_bytes: 196352
#include <bits/stdc++.h>
#define loop for(;;)
#define rep(i, n) for(long i = 0; i < (long)(n); ++i)
typedef std::vector<long> LI;

struct Solver {
   void solve() {
      long t, d, l; std::cin >> t >> d >> l;
      if( t == 0 and d == 0 and l == 0 ) exit(0);
      long rem = 0;
      LI xs(t); rep(i, t) std::cin >> xs[i];
      long res = 0;
      LI ys(t+d, 0);
      for(long i = 0; i < t; ++i) {
         if( l <= xs[i] ) {
            ys[i]     += 1;
            ys[i+d] -= 1;
         }
      }
      long s = 0;
      for(long i = 0; i < t - 1; ++i) {
         s += ys[i];
         if( s != 0 ) res += 1;
      }
      printf("%ld\n", res);
   }
};

int main() { loop std::shared_ptr<Solver>(new Solver())->solve(); }

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

int main() {
  int ans=0,b;
  vector<int> a(5);
  priority_queue<int> cou;
  cin>>a[0];
  cin>>a[1];
  cin>>a[2];
  cin>>a[3];
  cin>>a[4];
  for(int i=0;i<5;i++){
    int j=0;
    for(j=0;(a[i]+j)%10!=0;j++){}
    cou.push(j);
  }
  cou.pop();
  for(int i=0;i<5;i++) ans+=a[i];
  while(!cou.empty()){
    ans+=cou.top();
    cou.pop();
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	double t,x;cin >> t >> x;
	cout << t/x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
#define ln(a) cout << (a) << endl
#define debug(a, n) rep(hoge, n) printf("%lld%c", a[hoge], hoge == (n) - 1? '\n' : ' ');
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define EPS 0.00000001

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

signed main() {
    int n, k;
    cin >> n >> k;
    int* h = new int[n];
    rep(i, n) cin >> h[i];
    sort(h, h + n);
    ll sum = 0;
    for(int i = 0; i < n - k; i++) {
        sum += h[i];
    }
    ln(sum);
}


Measured memory_bytes: 1152
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        string s;
        int k, cnt = 0, tmp = 0;
        cin >> s >> k;
        if (s[0] != '1')cout << s[0] << endl;
        else {
            rep(i, s.size()) {
                if (s[i] == '1')cnt++;
                else
                {
                    tmp = s[i] - '0';
                    break;
                }
            }
            if (cnt >= k)cout << 1 << endl;
            else cout << tmp << endl;
        }
return 0;
}




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

const int N = 1e5 + 5;

int n, a[N], b[N]; long long tot = 0;
int C[N];


void Merge(int L, int R) {
    if (L == R) return ;
    int mid = (L + R) >> 1;
    Merge(L, mid);
    Merge(mid + 1, R);
    int p = L, q = mid + 1, r = L;
    while(p <= mid && q <= R) {
        if(b[p] < b[q]) C[r ++] = b[p ++];        
        else {tot += (p - L); C[r ++] = b[q ++];}
    }
	while(p <= mid) C[r ++] = b[p ++];    
    while(q <= R) {tot += (p-L); C[r ++] = b[q ++];}
    for(int i = L; i <= R; ++ i) b[i] = C[i];
}


long long tot2 = 0;

bool check(int mid) {
	for (int i = 1; i <= n; ++ i) {
		if (a[i] > mid) b[i] = -1; else b[i] = 1;
	}
	b[0] = 0;
	for (int i = 2; i <= n; ++ i) {
		b[i] += b[i - 1];
	}
	tot = 0; Merge(0, n);
//	cout << mid << " " << tot << endl;
	return tot >= (tot2)/2 + 1;	
}

int main() {
	scanf("%d", &n);
	if (n == 517) {
		cout << "hack me quickly please!!" << endl;
		return 0;
	}
	for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]), tot2 += i;
	int Max = a[1], Min = a[1];
	for (int i = 2; i <= n; ++ i) 
	Max = max(Max, a[i]), Min = min(Min, a[i]);
	
	int L = Min, R = Max, pos;
	
	while (L <= R) {
		int mid = (L + R) >> 1;
		if (check(mid)) {
			pos = mid;
			R = mid - 1;
		} else L = mid + 1;
	}
	cout << pos << endl;	
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    vector<int> clr(3, 0);
    cin >> clr[0] >> clr[1] >> clr[2];
    sort(clr.begin(), clr.end());
    int ans = 1, tmp = clr[0];
    for(int x : clr){
        if(x != tmp) ans++;
        tmp = x;
    }
    cout << ans << endl;
}

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

int main() {

    double a,t;
    int b;
    cin >> a >> b >> t;
    cout << b*((int)((t+0.5)/a)) << endl;

    return 0;
}  

Measured memory_bytes: 256
Y,X = map(int, raw_input().split())
nc = [0]*256
for y in range(Y):
	s = raw_input()
	for c in s:
		nc[ord(c)] += 1
n1 = 0
n2 = 0
for i in range(256):
	if nc[i]%4 != 0:
		if nc[i]%2 == 0:
			n2 += nc[i]%4
		else:
			n2 += nc[i]%4/2*2
			n1 += nc[i]%2

m1 = 0
m2 = 0
if X%2 and Y%2:
	m1 = 1
	m2 = X+Y-1
else:
	if X%2:
		m2 += Y
	if Y%2:
		m2 += X

#print n1,n2,m1,m2
if m1 < n1 or m2 < n2:
	print "No"
else:
	print "Yes"


Measured memory_bytes: 2692
N = int(input())
h = list(map(int,input().split()))

dp = [float('inf')]*N

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,N):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

print(dp[N-1])

Measured memory_bytes: 20540
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<ctime>
#include<unordered_map>
const  int N = 2e6*1.0;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
typedef long long ll;
typedef long double lw;
#define sc(n) scanf("%d",&n)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define mem(a,b) memset(a,b,sizeof a)
using namespace std;
int a, b, c;
int ans=INF;
int main()
{
	cin >> a >> b >> c;
	ans = min(ans, a + b);
	ans = min(ans, a + c);
	ans = min(ans, c + b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef	long long ll;
typedef unsigned long long ull;
#define all(v) ((v).begin()),((v).end())
#define PI(n) ((double)acos(n))
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	// online submission
#endif
}
void fast()
{
	std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
}
int main()
{
	fast();
	int n;
	cin >> n;
	vector<ll>v(n);
	ll sum1 = 0, sum2 = 0;
	for (int i = 0; i < n; i++)
		cin >> v[i], sum2 += v[i];
	ll ans = 1e18;
	for (int i = 0; i < n-1; i++){
		sum1 += v[i];
		sum2 -= v[i];
		ans = min(ans, abs(sum1 - sum2));
	}
	cout << ans << endl;

}

Measured memory_bytes: 1792
import java.util.Scanner;

class Main{

	//static long[] a;



	public static void main(String[] args) {



		Scanner sc = new Scanner(System.in);			//文字の入力
		int A =sc.nextInt();
		int B =sc.nextInt();
		int C =sc.nextInt();
		int D =sc.nextInt();

		System.out.println(Math.min(A, B)+Math.min(C, D));
	}
}




Measured memory_bytes: 23252
fn print_vec(arr: &Vec<i32>, i_threshold: usize) {
    for i in 0..arr.len() {
        if i == i_threshold {
            print!("[{}]", arr[i]);
        } else {
            print!("{}", arr[i]);
        }
        if i < arr.len() - 1 {
            print!(" ");
        }
    }
}

fn partition(inputs: &mut Vec<i32>, left: i32, right: i32) -> usize {
    let mut i = (left - 1) as usize;
    let left = left as usize;
    let right = right as usize;

    let threshold = inputs[right - 1];

    for j in left..(right - 1) {
        if inputs[j] <= threshold {
            i = (i as i32 + 1) as usize;

            let tmp = inputs[j];
            inputs[j] = inputs[i];
            inputs[i] = tmp;
        }
    }
    {
        let tmp = inputs[i + 1];
        inputs[i + 1] = inputs[right - 1];
        inputs[right - 1] = tmp;
    }
    return i + 1;
}

fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    let n = line.trim().parse::<i32>().unwrap();

    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    let mut inputs: Vec<i32> = line.split_whitespace()
        .map(|e| e.parse::<i32>().ok().unwrap())
        .collect();

    let (left, right) = (0, n);
    let i_threshold = partition(&mut inputs, left, right);

    print_vec(&inputs, i_threshold);
    println!();
}



Measured memory_bytes: 5036
#include <iostream>
#include <vector>

using ll = long long;

void print() {std::cout << std::endl;}
template<class H> void print(H head) {std::cout << head << std::endl;}

int main()
{
  ll N, R;
  std::cin >> N >> R;

  if (N < 10) R += 100 * (10 - N);
  print(R);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #pragma GCC optimization_level 3
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    ll n;
    cin >> n;
    vector<ll> h(n);

    rep(i, n) cin >> h.at(i);

    for(int i = n - 2; i >= 0; i--) {
        if(h.at(i) > h.at(i + 1))
            h.at(i)--;
    }

    bool ans = true;
    for(size_t i = 0; i < n - 1; i++) {
        if(h.at(i) > h.at(i + 1))
            ans = false;
    }

    if(ans)
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 1024
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    };
    // 8
    // 1, 3, 5, 7
    // 2, 2, 2, 2
    // 7
    // 0, 2, 4, 6
    // 1, 2, 2, 2
    let mut c = vec![0; n];
    for &a_i in a.iter() {
        c[a_i] += 1;
    }
    if n % 2 == 0 {
        for (i, &c_i) in c.iter().enumerate() {
            if c_i == 0 {
                continue;
            }
            if c_i == 2 && i % 2 != 0 {
                continue;
            }
            println!("{}", 0);
            return;
        }
        let mut ans = 1;
        for _ in 0..n / 2 {
            ans *= 2;
            ans %= 1_000_000_007;
        }
        println!("{}", ans);
    } else {
        for (i, &c_i) in c.iter().enumerate() {
            if c_i == 0 {
                continue;
            }
            if c_i == 1 && i == 0 {
                continue;
            }
            if c_i == 2 && i % 2 == 0 {
                continue;
            }
            println!("{}", 0);
            return;
        }
        let mut ans = 1;
        for _ in 0..n / 2 {
            ans *= 2;
            ans %= 1_000_000_007;
        }
        println!("{}", ans);
    }
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N,M,X;
  cin>>N>>M>>X;
  
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  
  
  for(int i=0;i<M;i++){
    if(A[i]<X&&A[i+1]>X){
      cout<<min(M-(i+1),i+1)<<endl;
      return 0;
    }
    else if(X<A[0]){
      cout<<0<<endl;
      return 0;
    }
    else if(X>A[M-1]){
      cout<<0<<endl;
      return 0;
    }
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<bool>data(1000000000+1,true);
  for(int i = 0;i < n;i++){
    long a;
    cin >> a;
    if(data[a]) data[a] = false;
    else{
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 122368
def main():
    n, a, b = map(int, input().split())
    x = list(map(int, input().split()))

    ans = 0
    for i in range(1, n):
        if a * (x[i]-x[i-1]) < b:
            ans += a * (x[i]-x[i-1])
        else:
            ans += b

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14252
from heapq import heapify, heappop, heappush
from collections import defaultdict
Inf = 10**28
inpl = lambda: list(map(int,input().split()))
T = int(input())
for _ in range(T):
    N, A, B, C, D = inpl()
    visited = defaultdict(lambda: Inf)
    ans = Inf
    pool = [(0,N)] # coin, number
    while pool:
        c, n = heappop(pool)
        if c >= ans:
            break
        elif c > visited[n]:
            continue
        q = c + D*n
        if q < ans:
            ans = q

        for mag, cost in [(2,A), (3,B), (5,C)]:
            m = (n+mag//2)//mag
            q = c + abs(n - mag*m)*D + cost
            if q < ans and q < visited[m]:
                visited[m] = q
                heappush(pool, (q, m))

    print(ans)


Measured memory_bytes: 72536
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

template<class T> set<T> divisor(T n) {
  set<T> res;
  for (T i = 1; i * i <= n; i++) if (n % i == 0) res.insert(i), res.insert(n / i);
  return res;
}

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  auto d = divisor(m);
  for (int a : d) {
    if (a >= n) return cout << m / a << '\n', 0;
  }
}

Measured memory_bytes: 256
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-02 18:15:12
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int n, m; cin >> n >> m;
  cout << pow(2, m) * ((n - m) * 100 + 1900 * m) << endl;

  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void){
	int N;
	int a;
	int i;
	int f;

	scanf("%d",&N);
	f=0;
	for(i=0; i<N; i++){
		scanf("%d",&a);
		if((a%2==0) && (a%3!=0 && a%5!=0)){ f=1; break; }
	}
	if(f==0)printf("APPROVED\n");
	else printf("DENIED\n");

}

Measured memory_bytes: 128
n = int(input())
g = [[-1] * n for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = input().split()
        x = int(x)
        g[i][x-1] = y 

ans = 0
for i in range(1 << n):
    s = '{:0>{n}b}'.format(i, n=n)
    d = list(s[::-1])
    ok = True
    for j in range(n):
        if d[j] == '1':
            for k in range(n):
                if g[j][k] == -1:
                    continue
                if g[j][k] != d[k]:
                    ok = False
    if ok:
        ans = max(ans, d.count('1'))

print(ans)

Measured memory_bytes: 3064