akhauriyash/Code-Regression huggingface dataset:
Operand =  ['+', '-', '*']

def calc(v1, v2, oprnd)
  case oprnd
    when '+'
      return v1 + v2
    when '-'
      return v1 - v2
    else
      return v1 * v2
  end
end

def getNewArray
  array = Array.new
  $stdin.gets.chomp.split(" ").each{|s| array << s.to_i }
  return array
end

def solve(perm, target)
  perm.each{|v|
    Operand.each{|o1|
      sum1 = calc(v[0], v[1], o1)
      Operand.each{|o2|
        sum2a = calc(sum1, v[2], o2)
        sum2b = calc(v[2], v[3], o2)
        Operand.each{|o3|
          sum3a = calc(sum2a, v[3], o3)
          sum3b = calc(sum1, sum2b, o3)
          if sum3a == target
            return "(((" + v[0].to_s + " " + o1 + " " + v[1].to_s + ")" + " " + o2 + " " + v[2].to_s + ")" + " " + o3 + " " + v[3].to_s + ")"
          end
          if sum3b == target
            return "((" + v[0].to_s + " " + o1 + " " + v[1].to_s + ")" + " " + o3 + " " + "(" + v[2].to_s + " " + o2 + " " + v[3].to_s + "))"
          end
        }
      }
    }
  }
  return 0
end

loop do
  array = getNewArray
  break if 0 == array.inject(:+)
  puts solve(array.permutation(4).to_a, 10)
end

Measured memory_bytes: 6132
#include <stdio.h>
int main(){
  int a,b,d,r;
  double f;
  scanf("%d %d",&a,&b);
  d=a/b;
  r=a%b;
  f=1.00000*a/b;
  printf("%d %d %lf\n",d,r,f);
  return 0;
}
  

Measured memory_bytes: 632
#include <bits/stdc++.h>
#include <climits>
#include <sstream>
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

// 二項係数計算
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;
}


// テーブルを作る前処理
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;
    }
}

using mint = Fp<MOD>;
//BiCoef<mint> bc;

int main() {
    
    long long N,M,K;
    cin >> N >> M >> K;
    //bc.init(510000);
    mint d = 0;
    
    for(int i = 1; i <N ;i++)d += M*M*i*(N-i);
    
    for(int i = 1; i <M ;i++)d += N*N*i*(M-i);
     COMinit();
    cout << d * COM(N*M-2, K-2) << endl;
    
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
const ll INFL = 1LL << 60;

class Solver {
  public:
    bool solve() {
        int L; cin >> L;
        vector<ll> A(L); cin >> A;
        vector<vector<ll>> dp(L + 1, vector<ll>(6, INFL));
        rep(i, 6) dp[0][i] = 0;
        rep(i, L) {
            auto f = [&] (int j) -> ll {
                switch(abs(2 - j)) {
                    case 2: return A[i];
                    case 1: return (A[i] == 0 ? 2 : A[i] % 2);
                    case 0: return A[i] % 2 == 0;
                }
                assert(false);
            };
            rep(j, 5) {
                set_min(dp[i + 1][j + 1], dp[i + 1][j]);
                set_min(dp[i + 1][j + 1], min(dp[i][j + 1], dp[i][j]) + f(j));
            }
        }

        cout << dp[L][5] << endl;

        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 19072
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>

typedef long double ld;
typedef long long ll;

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}

int main()
{
  ld R;
  std::cin >> R;

  const ld pi = acos(-1);

  std::cout << std::setprecision(16);
  print(2 * pi * R);

  return 0;
}


Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
int n,m,a[22],b[22],c,ans;
int main()
{
	cin>>n>>m>>c;
	for(int i=0;i<m;i++)
	{
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		memset(a,0,sizeof(a));
		for(int i=0;i<m;i++)
		{
			cin>>a[i];
		}
		int cnt=c;
		for(int i=0;i<m;i++)
		{
			cnt+=a[i]*b[i];
		}
		if(cnt>0)
		{
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 1e9+7;
const ll INF = 1LL<<40;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll a[60];
ll dp[60][60][3000];
int main(){
  ll n,x,ans=0;
  cin>>n>>x;
  rep(i,0,n)cin>>a[i];
  dp[0][0][0]=1;
  rep(i,0,n){
    rep(j,0,n){
      rep(k,0,2501) {
        if(dp[i][j][k]>0){
          dp[i+1][j][k]+=dp[i][j][k];
          dp[i+1][j+1][k+a[i]]+=dp[i][j][k];
        }
      }
    }
  }
  rep(i,1,n+1)ans+=dp[n][i][i*x];
  cout<<ans;
}

Measured memory_bytes: 69888
import math
n = int(input())
P = list(map(int, input().split()))

same = 0
cnt = 0
for i in range(n):
    if P[i] == i+1:
        same += 1
    else:
        cnt += math.ceil(same/2)
        same = 0

if same > 0:
    cnt += math.ceil(same/2)

print(cnt)

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

#define endl '\n'
#define int long long

const int N = 1e5 + 9;
int n;
int memo[N], h[N];

int dp(int id) {
	if(id >= n) return 1e9;
	if(id == n - 1) return 0;
	int &ans = memo[id];
	if(ans != -1) return ans;
	ans = min(dp(id + 1) + abs(h[id + 1] - h[id]), dp(id + 2) + abs(h[id] - h[id + 2]));
	return ans;
}

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

	memset(memo, -1, sizeof memo);
	cin >> n;
	for(int i = 0; i < n; i ++) cin >> h[i];
	cout << dp(0) << endl;


	return 0;
}

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

int main() {
    string N,hon,pon,bon;

    cin >> N;
    hon = "2,4,5,7,9";
    pon = "0,1,6,8";
    bon = "3";
    if (hon.find(N.at(N.size()-1)) != string::npos) {
        cout << "hon" << endl;
    } else if (pon.find(N.at(N.size()-1)) != string::npos) {
        cout << "pon" << endl;
    } else {
        cout << "bon" << endl;
    }
}


Measured memory_bytes: 3624
N = gets.to_i
str = gets.split("")

before = []
index1 = 0
index2 = 0

ans = 0

if N%2 == 1
    puts 'No'
else
    (N/2).times do
        before.push(str[index1])
        index1 += 1
    end
    
    (N/2).times do
        if before[index2] == str[index1]
            ans += 1
            index1 += 1
            index2 += 1
        else
            index1 += 1
            index2 += 1
        end
    end
    
    if ans == N/2
        puts 'Yes'
    else
        puts 'No'
    end
end


Measured memory_bytes: 1788
#include <stdio.h>

int main(void)
{
  int a, b;

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

  if (a < b) {
	puts("a < b");
  }
  else if (a > b) {
	puts("a > b");
  }
  else {
	puts("a == b");
  }

  return 0;
}

Measured memory_bytes: 580
import java.io.*;
import java.util.*;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long L;
        L = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(N, L);
    }
}

class Solver {
    public void solve(long N, long L) {
        long ans = 0;
        long min = Long.MAX_VALUE;
        long minScore = -1;
        for (int i = 0; i < N; i++) {
            long score = L + i;
            ans += score;

            if (min > Math.abs(score)) {
                min = Math.abs(score);
                minScore = score;
            }
        }
        System.out.println(ans - minScore);
    }
}



Measured memory_bytes: 21972
var
  x, y, s: longint;
begin
  read(x, y);
  case x of
    1: inc(s, 300000);
    2: inc(s, 200000);
    3: inc(s, 100000);
  end;
  case y of
    1: inc(s, 300000);
    2: inc(s, 200000);
    3: inc(s, 100000);
  end;
  if (x = 1) and (y = 1) then inc(s, 400000);
  writeln(s);
end.

Measured memory_bytes: 128
# coding: utf-8
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

sA=[0]
sB=[0]

def bin_isOK(index,key):
    if sB[index] <= key:
        return True
    else:
        return False


def binary_search(key):
    ng = len(sB)
    ok = -1

    while abs(ok - ng) >1:
        mid = (ok + ng)//2

        if bin_isOK(mid,key):
            ok = mid
        else:
            ng = mid
    
    return ok

for i in range(N):
    sA.append(sA[i]+A[i])
    
for i in range(M):
    sB.append(sB[i]+B[i])

ans=0
for i in range(len(sA)):
    if sA[i]>K:
        break
    j=binary_search(K-sA[i])
    ans=max(ans,i+j)
    
print(ans)




Measured memory_bytes: 126924
def game(dk, first):
    n = first
    while True:
        if len(dk[n]) == 0:
            return n.upper()
            break
        nn = dk[n][0]
        dk[n] = dk[n][1:]
        n = nn
    pass

dk = {}
dk["a"] = input()
dk["b"] = input()
dk["c"] = input()
print(game(dk,"a"))


Measured memory_bytes: 2940
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        ss: chars,
        tt: chars,
    };
    let mut s = ss.clone();
    let mut t = tt.clone();
    s.sort();
    t.sort_by(|a, b| b.cmp(a));
    let min_len = if s.len() < t.len() { s.len()} else { t.len()};
    for i in 0..min_len{
        if s[i] > t[i] {
            println!("No");
            return;
        }
        if s[i] < t[i] {
            println!("Yes");
            return;
        }
    }
    if s.len() >= t.len(){
        println!("No");
    } else {
        println!("Yes");
    }

}


Measured memory_bytes: 4352
import java.util.*;

class Main {

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

    while (true) {
      int h = sc.nextInt();
      int w = sc.nextInt();
      if (h == 0) return;

      int d = h * h + w * w;
      int minh = h, minw = w, mind = 22500+22500;
      for (int i = 1; i <= 150; i++) {
        for (int j = 1; j < i; j++) {
          int dd = i * i + j * j;
          if ( ((dd > d) || (dd == d && j > h)) && ((dd < mind) || (dd == mind && minh > j)) ) {
            minh = j;
            minw = i;
            mind = dd;
          }
        }
      }
      System.out.println(minh + " " + minw);
    }
  }
}



Measured memory_bytes: 27716
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<int> a(N);
	long long sum = 0;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		sum += a[i];
	}

	vector<long long> dp(N+1,0);
	long long res = 1000000000;
	for (int i = 0; i < N-1; ++i) {
		dp[i+1] += dp[i] + a[i];
		long long y = sum - dp[i+1];
		if (i == 0) {
			res = abs(dp[i+1]-y);
		}
		else if (abs(dp[i+1]-y) < res) {
			res = abs(dp[i+1]-y);
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>void print(T x){cout << x << endl;}
template<class T>void printvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
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; }
 
typedef pair<int, int> P;
int main()
{    
    int N, W; cin >> N >> W;
    vector<P> item(N);
    rep(i, N){
        cin >> item[i].first >> item[i].second;
    }

    ll sum=0; rep(i, N) sum+=item[i].second;
    vector<vector<ll>> dp(N+1, vector<ll>(sum+1, 1LL<<60));
    dp[0][0] = 0;
    
    FOR(i, 0, N){
        // rep(ii, N+1){
        //     rep(jj, sum+1){
        //         printf("%lld ", dp[ii][jj]);
        //     }
        //     printf("\n");
        // }
        // printf("\n");
        FOR(j, 0, sum+1){
            if(j-item[i].second>=0) chmin(dp[i+1][j], dp[i][j-item[i].second] + (ll)item[i].first);
            chmin(dp[i+1][j], dp[i][j]);
        }
    }

        //rep(ii, N+1){
        //     rep(jj, sum+1){
        //         printf("%lld ", dp[ii][jj]);
        //     }
        //     printf("\n");
        // }



    ll ans;
    rep(i, sum+1){
        if(dp[N][i]<=(ll)W) ans=i;
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <stdio.h>
#include <vector>
#define lld long long
 
using namespace std;
 
const lld MODULO = 1e9 + 7;
const int N = 2e5 + 5;
int n, m, t;
lld d[N], s[N], k[N], res;
vector <lld> F[N];
lld gcd, x, y;
 
void gener() {
    for (int i = 1; i <= max(m, n); i++) {
        k[i] = (k[i - 1] + (i - 1)) % MODULO;
        d[i] = (k[i] + d[i - 1]) % MODULO;
        s[i] = (s[i - 1] + k[i] * 2) % MODULO;
    }
}
 
void Clear() {
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= m; j++)
            F[i].push_back(0);
    for (int i = 1; i <= m; i++)
        F[1][i] = d[i];
    for (int i = 1; i <= n; i++)
        F[i][1] = d[i];
}
 
void print() {
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++)
            cout << F[i][j] << ' ';
        cout << '\n';
    }
}
 
void prepa() {
    gener();
    Clear();
    for (int i = 2; i <= n; i++)
        for (int j = 2; j <= m; j++) {
            lld temp = ((d[i] * j * j) % MODULO + (s[j] * k[i]) % MODULO + (d[j] * i) % MODULO) % MODULO;
            F[i][j] = temp;
        }
}
 
void extendedEuclid(lld A, lld B)
{
    if (B == 0)
    {
        gcd = A;
        x = 1;
        y = 0;
    }
    else
    {
        extendedEuclid(B, A%B);
        lld temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}
 
void solve()
{
    int q = t - 2;
    int p = n * m - 2;
    lld ngt = 1, n_k = 1, kgt = 1;
    for (int i = 1; i <= p; i++)
        ngt = (ngt * i) % MODULO;
    for (int i = 1; i <= q; i++)
        kgt = (kgt * i) % MODULO;
    for (int i = 1; i <= p - q; i++)
        n_k = (n_k * i) % MODULO;
    extendedEuclid(kgt, MODULO); kgt = x;
    extendedEuclid(n_k, MODULO); n_k = x;
    kgt = (kgt % MODULO + MODULO) % MODULO;
    n_k = (n_k % MODULO + MODULO) % MODULO;
    res = ((ngt * kgt % MODULO) * n_k % MODULO) * F[n][m] % MODULO;
    printf("%lld", res);
}
 
int main()
{
    //freopen("a.inp", "r", stdin);
    scanf("%d%d%d", &n, &m, &t);
        prepa();
        solve();
    return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

const ll MOD=1'000'000'007;

int N;
ll dp[101][4][4][4];

int main(){
    cin>>N;

    dp[0][3][3][3]=1;

    rep(i,N){
        rep(j,4){
            rep(k,4){
                rep(l,4){
                    if(dp[i][j][k][l]==0) continue;
                    rep(a,4){
                        if(k==0 && l==1 && a==2) continue;
                        if(k==1 && l==0 && a==2) continue;
                        if(k==0 && l==2 && a==1) continue;
                        if(j==0 && k==1 && a==2) continue;
                        if(j==0 && l==1 && a==2) continue;
                        dp[i+1][k][l][a]+=dp[i][j][k][l];
                        dp[i+1][k][l][a]%=MOD;
                    }
                }
            }
        }
    }

    ll ans=0;
    rep(i,4){
        rep(j,4){
            rep(k,4){
                ans+=dp[N][i][j][k];
            }
        }
    }
    ans%=MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pll pair<ll,ll>
#define pb push_back
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()

#define endl '\n'

ll power(ll a, ll b, ll mod){ ll c = 1; while(b>0){ if(b%2) c*=a, c%=mod; b/=2; a*=a; a%=mod; } return c; }
 
const ll N = (1e5) + 10;
const ll M = 320;
const ll Mod = 1e9 + 7;
ll x[N];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<setprecision(25);
    ll n,k,i,j,pos;
    cin>>n>>k; j = 0;
    for(i=0;i<n;i++){
    	cin>>x[i];
    	if(x[i] == 0) j=1, pos=i;
    	if(x[i] > 0 && j == 0){
    		x[i+1] = x[i]; x[i]=0; j=1; pos = i; i++; n++; k++; 
    	}
    }
    if(j == 0){
    	j=1; pos = n; x[pos]=0; n++; k++;
    }
    ll ans = 1e15;
    for(i=0;i<n;i++){
    	if(i == pos){
    		if(k == 1) ans = 0;
    	}
    	else if(i < pos){
    		if (pos-i+1 >= k) ans = min(ans, -x[i]);
    		else if(pos + (k-(pos-i+1)) < n) ans = min(ans, 2*(-x[i]) + x[pos + (k-(pos-i+1))] );
    	}
    	else{
    		if(i-pos+1 >= k) ans = min(ans, x[i]);
    		else if(pos - (k-(i-pos+1)) > 0) ans = min(ans, 2*x[i] + (-x[pos - (k-(i-pos+1))]));
    		// cout<<pos-(k-(i-pos+1))<<endl;
    	}
    	// cout<<ans<<' ';
    }
    // cout<<endl;
    cout<<ans<<endl;
    return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


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

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n;
    cin>>n;
    unordered_set<int> s;
    bool ok=true;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin>>a;
        if(s.find(a)!=s.end())
        {
            ok=false;
            break;
        }
        s.insert(a);
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
    return 0;
}

Measured memory_bytes: 8520
#include<iostream>
#include<queue>
#include<map>
#define S second
#define F first
using namespace std;
typedef pair<int,pair<int,pair<int,int> > > P;
int main(){
  int inf = 1<<20;
  int n,m,l,k,a,h;
  cin >> n >> m >> l >> k >> a >> h;
  while(n!=0){
    int i,j;
    int ma[105][105]={{}};
    fill(ma[0],ma[104],inf);
    int aa,b,c;
    bool ref[105];
    for(i=0;i<n;i++) ref[i]=false;
    for(i=0;i<l;i++){
      cin >> aa;
      ref[aa]=true;
    }
    for(i=0;i<k;i++){
      cin >> aa >> b >> c;
      ma[aa][b]=c;
      ma[b][aa]=c;
    }
    int d[105][105]={};
    fill(d[0],d[104],inf);
    P p,r;
    priority_queue <P,vector<P>,greater<P> > q;
    d[a][m]=0;
    p.F=0;p.S.F=a;p.S.S.F=m;p.S.S.S=0;
    q.push(p);
    int o=inf;;
    while(!q.empty()){
      p=q.top();q.pop();
      //cout << p.F<<":"<<p.S.F<<":"<<p.S.S<<endl;
      if(d[p.S.F][p.S.S.F]<p.F) continue;
      if(p.S.F==h) {
	o=min(o,p.F);
	if(p.S.S.S>0) o=min(o,p.F-min(p.S.S.F,p.S.S.S));
	continue;
      }
      for(i=0;i<n;i++){
	if(p.S.S.F>=ma[p.S.F][i]){
	  if(d[p.S.F][p.S.S.F]+ma[p.S.F][i]<d[i][p.S.S.F-ma[p.S.F][i]]){
	    d[i][p.S.S.F-ma[p.S.F][i]]=d[p.S.F][p.S.S.F]+ma[p.S.F][i];
	    r.F=d[i][p.S.S.F-ma[p.S.F][i]];
	    r.S.F=i;
	    r.S.S.F=p.S.S.F-ma[p.S.F][i];
	    r.S.S.S=p.S.S.S;
	    q.push(r);
	  }
	}
	if(ref[p.S.F]){
	  //cout << i << endl;
	  //for(j=1;p.S.S+j<=m;j++){
	  j=m-p.S.S.F;
	    if(p.S.S.F+j>=ma[p.S.F][i]){
	      if(d[p.S.F][p.S.S.F]+j+ma[p.S.F][i]<d[i][p.S.S.F+j-ma[p.S.F][i]]){
		d[i][p.S.S.F+j-ma[p.S.F][i]]=d[p.S.F][p.S.S.F]+j+ma[p.S.F][i];
		r.F=d[i][p.S.S.F+j-ma[p.S.F][i]];
		r.S.F=i;
		r.S.S.F=p.S.S.F+j-ma[p.S.F][i];
		r.S.S.S=p.S.S.S+j;
		q.push(r);
	      }
	    }
	    //} 
	}
      }
    }
    
    if(o==inf) cout << "Help!" << endl;
    else cout << o << endl;
    cin >> n >> m >> l >> k >> a >> h;
  }
  return 0;
}

Measured memory_bytes: 1420
mod = 1000000007

n,m = map(int,input().split())
vals = [0 for i in range(n+2)]
for i in range(m):
	vals[int(input())] = 1

ans = [0 for i in range(n+2)]
ans[n]=1
for i in range(n-1,-1,-1):
	if vals[i+1] == 0:
		ans[i] += ans[i+1]
	if vals[i+2] == 0:
		ans[i] += ans[i+2]
	
print(ans[0]%mod)

Measured memory_bytes: 469744
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
a = na()

def gcd(m, n):
    if n == 0:
        return m
    else:
        return gcd(n, m % n)

res = 0
for i in a:
    res = gcd(i, res)

print(res)

Measured memory_bytes: 14168
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            string w = Console.ReadLine();
            int n = 0;

            //for (int i = 0; i < 3; i++)
            //{
            //    if (w[i] == '1') n++;
            //}

            int s1 = w[0] - '0';
            int s2 = w[1] - '0';
            int s3 = w[2] - '0';

            if (s1 == 1) n++;
            if (s2 == 1) n++;
            if (s3 == 1) n++;


            Console.WriteLine(n);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

int main()
{
  int n, k;
  scanf("%d%d", &k, &n);
  VI V;
  FOR(i, 1, n)
    {
    int a;
    scanf("%d",&a);
    V.PB(a);
    }
  sort(ALL(V));

  int res = 0;
  FOR(i, 1, n-1)
    {
    maxi(res, V[i] - V[i-1]);
    }
  maxi(res, (V[0] + k - V.back()));
  cout << k - res << endl;
}


Measured memory_bytes: 1400
/*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0021&lang=jp
*/

#include<stdio.h>
#include<math.h>

const double eps=1e-10;
int n,i;
double ax,ay,bx,by,cx,cy,dx,dy;


int solve(void){
    double Ax=bx-ax;
    double Ay=by-ay;
    double Bx=dx-cx;
    double By=dy-cy;

    double val=fabs(Ax*By-Ay*Bx);

    return (fabs(val)<eps);
}

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

    for(i=0;i<n;i++){
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy);

        if(solve()){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2008
using System;

namespace ABC046B
{
    class Program
    {
        static void Main(string[] args)
        {
            var target = Console.ReadLine().Split(' ');
            long N = long.Parse(target[0]);
            long K = long.Parse(target[1]);
            Console.WriteLine("{0}", (long)(K*Math.Pow(K-1, N-1)) );
        }
    }
}


Measured memory_bytes: 11220
def solve(string):
    m = 10**9 + 7
    a, b = 0, 1
    for l in string:
        a, b = ((3 * a + b) % m, 2 * b % m) if int(l) else (3 * a % m, b)
    return str((a + b) % m)


if __name__ == '__main__':
    print(solve(input()))


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

int main() {
  int a, b;
  std::cin >> a>>b;
  if (a + b ==15){
    std::cout << "+" << '\n';
  }
  else if (a * b == 15) {
    std::cout << "*" << '\n';
  }
  else{
    std::cout << "x" << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <cmath>
class Town {
	std::vector<std::pair<long long int, int>> mStack{};
public:
	void addEdge(const long long int cost, const int toTown) {
		mStack.push_back(std::make_pair(cost, toTown));
	}
	const std::vector<std::pair<long long int, int>> rails() const {
		return mStack;
	}
};
std::vector<long long int> searchMinPath(const std::vector<Town> &towns, const int start) {
	auto comparator = [](const std::pair<long long int, int> a, const std::pair<long long int, int> b) {return a.first > b.first; };
	auto queue = std::priority_queue<std::pair<long long int, int>, std::vector<std::pair<long long int, int>>, decltype(comparator)>(comparator);
	auto minCost = std::vector<long long int>(towns.size(), LLONG_MAX);
	minCost[start] = 0;
	queue.push(std::make_pair(minCost[start], start));
	while (queue.size() != 0) {
		auto top = queue.top(); queue.pop();
		if (minCost[top.second] == top.first) {
			for (const auto rail : towns[top.second].rails()) {
				if (minCost[rail.second] > top.first + rail.first) {
					minCost[rail.second] = top.first + rail.first;
					queue.push(std::make_pair(minCost[rail.second], rail.second));
				}
			}
		}
	}
	return minCost;
}
int main() {
	constexpr long long int money = 1000000000000000L;
	int n, m, s, t; std::cin >> n >> m >> s >> t;
	auto townsYen = std::vector<Town>(n);
	auto townsSnuke = std::vector<Town>(n);
	for (auto i = 0; i < m; ++i) {
		int u, v; long long int a, b;
		std::cin >> u >> v >> a >> b;
		townsYen[u - 1].addEdge(a, v - 1);
		townsYen[v - 1].addEdge(a, u - 1);
		townsSnuke[u - 1].addEdge(b, v - 1);
		townsSnuke[v - 1].addEdge(b, u - 1);
	}
	auto minYenFromStart = searchMinPath(townsYen, s - 1);
	auto minSnukeFromGoal = searchMinPath(townsSnuke, t - 1);
	auto minCost = std::vector<long long int>(n);
	for (auto i = 0; i < n; ++i) minCost[i] = minYenFromStart[i] + minSnukeFromGoal[i];
	for (int i = n - 1; i > 0; --i) minCost[i - 1] = std::min(minCost[i], minCost[i - 1]);
	for (const auto min : minCost) {
		std::cout << money - min << std::endl;
	}
}


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

const int N = 201000;

int up[N], fa[N], ans[N], pos[N], st[N], top, n, p[N], siz[N], del[N];
vector<int> sub[N], g[N];

void Dfs(int x) {
  if(x) {
    up[x] = max(fa[x], up[fa[x]]);
    sub[up[x]].push_back(x);
  }
  for(int v : g[x]) {
    if(v == fa[x]) {
      continue;
    }
    fa[v] = x;
    Dfs(v);
  }
}

void Solve(int x) {
  //cerr << fa[x] << " " << x << endl;
  st[++top] = x;
  pos[x] = top;
  if(x) {
    ans[x] += ans[up[x]] - del[st[pos[up[x]] + 1]];
  }
  for(int v : g[x]) {
    if(v == fa[x]) {
      continue;
    }
    Solve(v);
  }
  --top;
}

int Find(int x) {
  return p[x] == x ? x : p[x] = Find(p[x]);
}

int main(void) {
  scanf("%d", &n);
  for(int i = 1, x, y; i < n; i++) {
    scanf("%d%d", &x, &y);
    x--; y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  Dfs(0);
  //cerr << "!" << endl;
  for(int i = 1; i < n; i++) {
    //cerr << fa[i] << endl;
    p[i] = i;
    siz[i] = 1;
  }
  for(int i = 0; i < n; i++) {
    for(int x : sub[i]) {
      if(x < i) {
	ans[x] = siz[Find(x)];
      } else {
	ans[x] = 1;
	for(int y : g[x]) {
	  if(y < i) {
	    if(fa[x] != y) {
	      del[y] = siz[Find(y)];
	    }
	    ans[x] += siz[Find(y)];
	  }
	}
      }
    }
    for(int j : g[i]) {
      if(j < i) {
	int x = Find(i), y = Find(j);
	p[x] = y;
	siz[y] += siz[x];
      }
    }
  }
  //cerr << "!" << endl;
  Solve(0);
  //cerr << "!" << endl;
  for(int i = 1; i < n; i++) {
    printf("%d%c", ans[i], i == n - 1 ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 33784
s=input()
s_list=list(s)
count=0
for i in range(len(s)-1):
    if s_list[i]==s_list[i+1]:
        if s_list[i+1]=='0':
            s_list[i+1]='1'
        else:
            s_list[i+1]='0'
        count+=1
        
print(count)

Measured memory_bytes: 3956
#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 watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF ll(1e18)
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define MAXN 100005

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	ll n; cin>>n;
	
	if(n%2==1){
		cout<<0<<'\n';
		return 0;
	}
	
	bool c=0;
	ll x=10;
	ll ans=0;
	while(n/x){
		ans+=n/x;
		if(!c) x*=5;
		else x*=10;
	}
	
	cout<<ans<<'\n';
	
	return 0;
}


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

int main()
{
    int a,b,k,i,j;
    cin>>a>>b>>k;

    int d=b-a+1;
    if(k>=d){
            j=0;
        for(i=0;(i<=b-1)&&(j<d);j++,i++){
            cout<<a+i<<endl;
        }
    }
    else if(k>(d/2))
    {
        for(i=0;i<k;i++){
            cout<<a+i<<endl;
        }
        for( j=d-k-1;j>=0;j--){
            cout<<b-j<<endl;
        }
    }
    else if(k<d)
    {
        for(i=0;i<k;i++){
            cout<<a+i<<endl;
        }
        for(j=k-1;j>=0;j--){

            cout<<b-j<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
import Data.List
  ( sort, sortBy )

main :: IO ()
main = do
  s <- getLine
  t <- getLine
  putStrLn $ if s `isLargerThan` t 
               then "Yes"
               else "No"

isLargerThan
  :: String -> String -> Bool
isLargerThan s t
  | s' < t'   = True
  | otherwise = False
  where
    s' = toLeft  s
    t' = toRight t

    toLeft  = sort
    toRight = sortBy (flip compare)

Measured memory_bytes: 508
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位


signed main() {
	string s;
	cin >> s;
	int w;
	cin >> w;
	for (int i = 0; i < s.length(); i += w) {
		cout << s[i];
	}
	cout << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <numeric>
#include <iomanip>

int main(void) {
	int n;

	std::cin >> n;

	std::vector<int> v(n);

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

	std::sort(v.begin(), v.end());
	std::reverse(v.begin(), v.end());

	int sum = std::accumulate(v.begin(), v.end(), 0);

	sum -= v[0];

	if (v[0] < sum) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
using ll = long long;
int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i=0;i<n;i++){
        ll x;
        cin >> x;
        ans+=x-1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


ll N;
ll A[200005];

int main(){

	scanf("%lld",&N);

	A[0] = 0;
	for(ll i = 1; i <= N; i++){

		scanf("%lld",&A[i]);
		A[i] += A[i-1];
	}

	ll ans = HUGE_NUM;
	ll l_r = 1,r_r = 3;

	for(ll mid = 2; mid <= N-2; mid++){ //1～midが左の2グループ

		ll sum_L = A[mid];

		ll maximum = -HUGE_NUM;
		ll minimum = HUGE_NUM;

		while(l_r+1 <= mid-1 && abs((sum_L-A[l_r+1])-A[l_r+1]) < abs((sum_L-A[l_r])-A[l_r]))l_r++;

		maximum = max(maximum,max(A[l_r],sum_L-A[l_r]));
		minimum = min(minimum,min(A[l_r],sum_L-A[l_r]));


		ll sum_R = A[N]-A[mid];
		r_r = max(r_r,mid+1);

		while(r_r+1 <= N-1 && abs((sum_R-(A[r_r+1]-A[mid]))-(A[r_r+1]-A[mid])) <  abs((sum_R-(A[r_r]-A[mid]))-(A[r_r]-A[mid])))r_r++;

		maximum = max(maximum,max(A[r_r]-A[mid],sum_R-(A[r_r]-A[mid])));
		minimum = min(minimum,min(A[r_r]-A[mid],sum_R-(A[r_r]-A[mid])));

		ans = min(ans,maximum-minimum);
	}

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

	return 0;
}


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

int cover[200010],cnt[200010],ans,a[200010];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	ans=n;
	for(int i=1,x;i<=n;i++){
		cin>>x;
		cnt[x]++;
		int z = x+1-cnt[x];
		if(z>=1){
			if(cover[z]==0)	ans--;
			cover[z]++;
		}
		a[i]=x;
	}
	while(m--){
		int x,y;
		cin>>x>>y;
		int w = a[x],z=w+1-cnt[w];
		cnt[w]--;
		if(z>=1){
			cover[z]--;
			if(cover[z]==0)	ans++;
		}
		a[x]=y;
		cnt[y]++;
		z = y+1-cnt[y];
		if(z>=1){
			if(cover[z]==0)	ans--;
			cover[z]++;
		}
		cout<<ans<<'\n';
	}
}


Measured memory_bytes: 3840
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input[] = br.readLine().split(" ");

		for (int i = 0; i < Integer.parseInt(input[0]); i++) {
			String and =br.readLine();
			for (int j = 0; j < 2; j++) {
				System.out.println(and);
			}
		}

	}

}


Measured memory_bytes: 21332
// https://atcoder.jp/contests/abc063/tasks/abc063_b

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

bool unique(string s)
{
  int len = s.length();

  REP(i, len - 1)
  {
    FOR(j, i + 1, len)
    {
      if (s[i] == s[j])
        return false;
    }
  }
  return true;
}

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  string s, r;

  cin >> s;

  r = unique(s) ? "yes" : "no";

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr int MOD = 1000000007;
constexpr int INF = 1e18;

using namespace std;


signed main() {
  int N;
  cin >> N;

  vector<vector<int>> vec(N, vector<int>(N, INF));

  REP(i, N) REP(j, N){
    int a = i+1, b = j+1;
    int cnt = 1;
    while(a || b){
      if(a%2 != b%2) break;
      cnt++;
      a /= 2; b /= 2;
    }
    vec[i][j] = cnt;
  }

  REP(i, N) FOR(j, i+1, N){
    cout << min(vec[i][j], vec[j][i]);
    SPBR(j, N);
  }

  return 0;
}

Measured memory_bytes: 2432
#include<stdio.h>
int main(void){
	int a[3],sum=0;
	scanf("%1d%1d%1d",&a[0],&a[1],&a[2]);
	for(int i=0;i<3;i++){
		if(a[i]==1)sum++;
	}
	printf("%d",sum);
	return 0;
}

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

#define pb                push_back
#define mp                make_pair
#define all(x)            (x).begin(),(x).end()
#define fi                first
#define se                second
#define vc                vector
#define pii               pair<bint,bint>
#define endl              "\n"
#define rep(i,a,b)        for(bint i=a;i<b;i++)
#define repe(i,a,b)       for(bint i=a;i<=b;i++)
#define bac(i,a,b)        for(bint i=a;i>b;i--)
#define bace(i,a,b)       for(bint i=a;i>=b;i--)
#define fast              ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

//CHANGE IF REQ
#define int               long long int
#define bint              int
//-----------------

#define ld                long double
#define mod1              (bint)(1e9 + (bint)7)
#define mod2              (bint)998244353
#define pi                (float)3.14159265358979323846
#define inf               LLONG_MAX
#define ninf              (bint)-1*LLONG_MAX

#define DECIMAL(n)        std::cout << std::fixed << std::setprecision(n)
#define SORT(v)           sort(all(v))
#define RSORT(v)          sort(all(v),greater<bint>())
#define REVERSE(v)        reverse(all(v))

#define trav(a, x)        for(auto& A : x)
#define display(x)        trav(A,x) cout<<A<<endl;
#define pow(i,n)          (bint)pow((bint)i,n)
#define pow2(n)           ((bint)1<<n)
#define sz(x)             (bint)x.size()

typedef std::priority_queue<bint, std::vector<bint>, std::greater<bint> > min_pq;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

inline string inttos(bint a){std::stringstream soso; soso<<a; return soso.str();}
inline bint stoint(const std::string &s) {std::stringstream soso; soso << s; long long x; soso >> x; return x;}
inline std::string inttobin(bint x) {return std::bitset<40>(x).to_string();}
inline void swp(bint &a, bint &b){auto temp=a;a=b;b=temp;}

//pri - 1000000009
//ba  - 937,991,1013,1409,1741

void solve(){
    int n,m;
    cin>>n>>m;
    int sum=0;
    rep(i,0,m){
        int x;
        cin>>x;
        sum+=x;
    }
    if(sum>n){
        cout<<"-1"<<endl;
    }
    else{
        cout<<n-sum<<endl;
    }
}


signed main(){
    fast

    int t=1;
    //cin>>t;
    rep(i,0,t){
       solve();
    }
}

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

int main(){
  ll N;cin>>N;
  vector<ll> a(N);rep(i,N)cin>>a[i];
  cout << accumulate(a.begin(),a.end(),0) - N << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		InputReader r = new InputReader(System.in);
		int n = r.nextInt();
		int[] arr = new int[2 * n];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = r.nextInt();
		}
		Arrays.sort(arr);
		int res = 0;
		for (int i = 0; i < arr.length; i += 2) {
			res += arr[i];
		}
		System.out.println(res);
	}

	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}

		public InputReader(FileReader stream) {
			reader = new BufferedReader(stream);
			tokenizer = null;
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


Measured memory_bytes: 7764
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <queue>
#include <memory>
#include <fstream>

#pragma GCC optimize("no-stack-protector,Ofast,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,abm,mmx,tune=native,avx,avx2")

#define int long long
#define ld long double
#define eb emplace_back
#define pb pop_back
#define mp make_pair
#define ss second
#define ff first
#define sqr(x) (x) * (x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair < int, int >
#define vi vector < int >
#define vvi(x, y) vector < vi > (x, vi(y))

typedef int(*func)(int a, int b);

using namespace std;

random_device rd;
mt19937 get_rand(rd());

template < typename T1, typename T2 >
istream& operator>>(istream& in, pair < T1, T2 >& p) {
	in >> p.ff >> p.ss;
	return in;
}

template < typename T1, typename T2 >
ostream& operator<<(ostream& out, pair < T1, T2 >& p) {
	out << p.ff << ' ' << p.ss;
	return out;
}

template < typename T1 >
istream& operator>>(istream& in, vector < T1 >& v) {
	for (int i = 0; i < sz(v); i++)
		in >> v[i];
	return in;
}

template < typename T1 >
ostream& operator<<(ostream& out, vector < T1 >& v) {
	for (int i = 0; i < sz(v); i++)
		out << v[i] << ' ';
	out << '\n';
	return out;
}

int gcd(int a, int b) {
	return (!a ? b : gcd(b % a, a));
}

const int INF = 1e9 + 7;
const int B = 100003;
const int MOD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.14159265358979323;
const int MAXLL = 9223372036854775807;

bool npr[10000010];

signed main() {
	//ifstream cin("kdivision.in");
	//ofstream cout("kdivision.out");
#ifdef _LOCAL
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	srand(time(NULL));

	int ttt = 1;
	//cin >> ttt;
	while (ttt--) {
		int n;
		cin >> n;
		int n1 = 100, k = 0;
		while (n1 < n) {
			n1 = n1 + n1 / 100;
			k++;
		}
		cout << k << '\n';
	}
	return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>

void even_line(int w) {
    int i;

    for (i=0; i<w; i++) {
        if (i%2 == 0) {
	    printf("#");
	    continue;
	}
	printf(".");
    }
}

void odd_line(int w) {
    int i;

    for (i=0; i< w; i++) {
        if (i%2 == 0) {
	    printf(".");
	    continue;
	}
	printf("#");
    }
}

void draw(int h, int w) {
    int i;

    for (i=0; i<h; i++) {
        if (i%2 == 0) {
	    even_line(w);
	} else {
            odd_line(w);
        }
	printf("\n");
    }
}

void process() {
    int h, w;

    do {
        scanf("%d %d", &h, &w);
	if (h == 0 && w == 0) break;
	draw(h, w);
	printf("\n");
    } while (h != 0 || w != 0);
}

int main(void) {
    process();
    return 0;
}


Measured memory_bytes: 2100
import sys
input = sys.stdin.readline

N, M, K = map(int, input().split())
tempA = [int(i) for i in input().split()]
tempB = [int(i) for i in input().split()]
A = [0] * (N+1)
for i in range(1, N+1):
    A[i] = A[i-1] + tempA[i-1]
B = [0] * (M+1)
for i in range(1, M+1):
    B[i] = B[i-1] + tempB[i-1]

ans = 0
for a in range(N+1):
    if A[a] > K:
        break
    for b in range(ans-a+1, M+1):
        if A[a] + B[b] <= K:
            ans = max(ans, a+b)
        else:
            break

print(ans)

Measured memory_bytes: 118256