akhauriyash/Code-Regression huggingface dataset:
(let ((x (read))
    (k (read))
    (dr (read))
    (nokori 0)
    (ans 0))
    (if (>= x 0)
        (if (>= (- x (* k dr)) 0)
            (setq x (- x (* k dr)))
            (progn
                (setq nokori (- k (floor (/ x dr))))
                (setq x (- x (* (- k nokori) dr)))                
            )
        )
        (if (<= (+ x (* k dr)) 0)
            (setq x (+ x (* k dr)))
            (progn
                (setq nokori (- k (floor (/ (abs x) dr))))
                (setq x (+ x (* (- k nokori) dr)))
            )
        )

    )
    (if (zerop (rem nokori 2))
        (princ (abs x))
        (if (<= x 0)
            (princ (abs (+ x dr)))
            (princ (abs (- x dr)))
        )
    )
)

Measured memory_bytes: 24560
#include<bits/stdc++.h>
using namespace std;
int a[10];
int vis[10];
bool check(int x)
{
    while(x)
    {
        if(vis[x%10])return 0;
        x/=10;
    }
    return true;
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=1;i<=k;i++)
    {
        scanf("%d",&a[i]);
        vis[a[i]]++;
    }
    //不能包含数字ai，求最小钱数
    int i;
    for(i=n;;i++)
    {
        if(check(i))break;
    }
    printf("%d\n",i);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
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 MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    vector<ll> sum(n + 1, 0);
    REP(i, n) sum[i + 1] = sum[i] + a[i];

    ll ans = LINF;
    int l = 1;
    int r = 3;
    FOR(i, 2, n - 1) {
        ll d = abs(sum[l] - sum[0] - (sum[i] - sum[l]));
        while (l < i - 1) {
            ll f = abs(sum[l + 1] - sum[0] - (sum[i] - sum[l + 1]));
            if (d > f) {
                d = f;
                l++;
            } else {
                break;
            }
        }
        if (i >= r) r = i + 1;
        d = abs(sum[r] - sum[i] - (sum[n] - sum[r]));
        while (r < n - 1) {
            ll f = abs(sum[r + 1] - sum[i] - (sum[n] - sum[r + 1]));
            if (d > f) {
                d = f;
                r++;
            } else {
                break;
            }
        }
        chmin(ans, max({sum[l] - sum[0], sum[i] - sum[l], sum[r] - sum[i], sum[n] - sum[r]}) - min({sum[l] - sum[0], sum[i] - sum[l], sum[r] - sum[i], sum[n] - sum[r]}));
    }
    cout << ans << EOL;
}


Measured memory_bytes: 3328
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let s: String = input();
    let s: Vec<char> = s.chars().collect();
    let t: String = input();
    let t: Vec<char> = t.chars().collect();
    
    for i in 0..(s.len() - t.len() + 1) {
        let i_rev = s.len() - i - t.len();
        let mut flag = true;
        for j in 0..t.len() {
            if s[i_rev+j] == t[j] || s[i_rev+j] == '?' {
            } else {
                flag = false;
            }
        }
        if flag {
            for i in 0..s.len() {
                if i == i_rev {
                    for c in &t {
                        print!("{}", c);
                    }
                }
                if i >= i_rev && i < i_rev + t.len() {
                    continue;
                }
                if s[i] == '?' {
                    print!("a");
                } else {
                    print!("{}", s[i]);
                }                
            }
            return;
        }
    }
    println!("UNRESTORABLE")
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n+2);
    a[0] = 0;
    a[n+1] = 0;
    for(int i = 1; i <= n; i++) cin >> a[i];

    int sum = 0;
    for(int i = 1; i <= n+1; i++){
        sum += abs(a[i]-a[i-1]);
    }
    for(int i = 1; i <= n; i++){
        int ans = sum;
        ans -= abs(a[i]-a[i-1]);
        ans -= abs(a[i]-a[i+1]);
        ans += abs(a[i-1]-a[i+1]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3684
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum, ans, d[3000][3000], a[2000000], b[2000000];
string str;
bool f;
double Ans;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[1000000];
vector<Pll>v;
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


int main() {
	cin >> n>>m;
	ans = INF;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) 
		rep(j, n) 
			d[i][j] = INF;
	rep(i, n) {
		rep(j, n) {
			d[i][(i + j) % n] = min({ a[(i + j) % n],d[i][(i + j) % n] });
			if (j > 0)
				d[i][(i + j) % n] = min(d[i][(i + j) % n], d[i][(i + j - 1) % n]);
		}
	}
	rep(i, n) {
		cnt = m*i;
		rep(j, n) {
			cnt+=min(d[(j-i+n) % n][j],a[j]);
		}
		ans = min(ans,cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 76032
#include <iostream>

using namespace std;

const int cost[] = {600, 800, 1000, 1200, 1400, 1600};

int main()
{
    int n;

    while (cin >> n, n) {
        int size[6];
        int x, y, h, w;
        long long ans = 0;


        for (int i = 0; i < 6; i++)
            size[i] = 0;

        for (int i = 0; i < n; i++) {
            cin >> x >> y >> h >> w;
            
            x += y + h;
            if (x <= 60 && w <= 2)
                size[0]++;
            else if (x <= 80 && w <= 5)
                size[1]++;
            else if (x <= 100 && w <= 10)
                size[2]++;
            else if (x <= 120 && w <= 15)
                size[3]++;
            else if (x <= 140 && w <= 20)
                size[4]++;
            else if (x <= 160 && w <= 25)
                size[5]++;
        }
        for (int i = 0; i < 6; i++)
            ans += cost[i] * size[i];
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1156
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

public class Main {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[] s = br.readLine().split(" ", 0);
        int n = Integer.parseInt(s[0]);
        int q = Integer.parseInt(s[1]);
        
        Queue[] pq = new Queue[n];
        for (int i = 0; i < n; i++) {
            pq[i] = new Queue();
        }
        
        String[] l;
        String command;
        int t, x;
        for (int i = 0; i < q; i++) {
            l = br.readLine().split(" ", 0);
            command = l[0];
            t = Integer.parseInt(l[1]);
            switch (command) {
                case "0":
                    x = Integer.parseInt(l[2]);
                    pq[t].insert(x);
                    break;
                case "1":
                    pq[t].getMax();
                    break;
                case "2":
                    pq[t].deleteMax();
                    break;
            }
        }
    }
}

class Queue {
    ArrayList<Integer> a;
    
    Queue() {
        a = new ArrayList<Integer>();
    }
    
    void insert(int x) {
        int size = a.size();
        if (size == 0) {
            a.add(x);
            return;
        }
        int p = binarySearch(x, 0, a.size() - 1);
        //System.out.println("size = " + a.size());
        //System.out.println("inserted: p=" + p);
        if (p == a.size()) {
            a.add(x);
        } else {
            a.add(p, x);
        }
    }
    
    void getMax() {
        int size = a.size();
        if (size != 0) {
            System.out.println(a.get(size - 1));
            //System.out.println(a);
        }
    }
    
    void deleteMax() {
        int size = a.size();
        if (size != 0) {
            a.remove(size - 1);
        }
    }
    
    int binarySearch(int num, int l, int r) {
        if (l >= r - 1) {
            if (num <= a.get(l)) {
                return l;
            } else if (a.get(r) <= num) {
                return r + 1;
            } else {
                return l + 1;
            }
        }
        int m = (l + r) / 2;
        int ret;
        if (a.get(m) == num) {
            ret = m;
        } else if (num < a.get(m)) {
            ret = binarySearch(num, l, m - 1);
        } else {
            ret = binarySearch(num, m + 1, r);
        }
        return ret;
    }
}

    



Measured memory_bytes: 70548
// ~maqsat~
/*    
**    “Anyone who has never made a mistake has never tried anything new.”
**    © Albert Einstein
*/

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void cmin(T &a, T b) { a = min(a, b); }
template <class T> inline void cmax(T &a, T b) { a = max(a, b); }

const int oo = 0x3f3f3f3f;
const ll N = 1e5 + 345;
const ll MOD = 1e9 + 7;
const ll INF = 1e10 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

int main() {
    fre("");
    ACCELERATE;
	
	int a, b, c;
	cin >> a >> b >> c;

	ll ans = min(a, c);
	c = max(0, c - a);

	if(c) {
		int x = min(b, c);
		ans += x * 2;
		b -= x;
		c -= x;
	}
	else {
		ans += b;
		b = 0;
	}

	if(b) {
		ans += b;
		b = 0;
	}
	else if(c) {
		ans++;
	}

	cout << ans;
    return 0;
}
/*
 
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll INF = 1e18;
int MOD = 1e9+7;
ll combi(ll n,ll r){
    ll num = 1;
    for(ll i = 1;i <= r;i++){
        num = (n-i+1)*num / i;
    }
    return num;
}
main(){
    int N,A,B;
    cin >> N >> A >> B;
    vector<ll> V(N);
    map<ll,int> mp;
    for(int i = 0;i < N;i++){
        cin >> V[i];
        mp[V[i]]++;
    }
    sort(V.rbegin(),V.rend());
    ll sum = 0,ans = 0;
    for(int i = 0;i < A;i++)sum += V[i];
    for(int i = A;i <= B;i++){
        map<ll,int>tmp;
        ll minv = INF;
        for(int j = 0;j < i;j++){
            tmp[V[j]]++;
            minv = min(minv,V[j]);
        }
        if(i != A && tmp.size() != 1)break;
        ans += combi(mp[minv],tmp[minv]);
    }
    printf("%.6lf\n",1. * sum / A);
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque
from collections import Counter
n=int(input())
if n<357:
    print(0)
    exit()
i=357
ans=0
while i<=n:
  c=Counter(str(i))
  if '3' in c and '5' in c and '7' in c:
    if c['3']+c['5']+c['7']==len(str(i)):
      ans+=1
  a=list(map(int,list(str(i))))
  a[-1]+=2
  j=-1
  while a[j]>7 and -j<len(a):
    a[j]=3
    a[j-1]+=2
    j-=1
  if a[0]>7:
    a[0]=33
  i=int(''.join(map(str,a)))

print(ans)


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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  vector<ll>p(n);
  rep(i,0,n)cin>>p[i];
  vector<ld>a(n+1);
  rep(i,0,n)a[i+1]=a[i]+ld(1+p[i])/2;
  ld ret=0;
  rep(i,0,n-k+1){
    chmax(ret,a[i+k]-a[i]);
  }
  lfs<<ret<<endl;
  return 0;
}

Measured memory_bytes: 4992
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//ここまでテンプレ
//↓Union-Find Tree
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};
//↑Union-Find Tree
int main(){
	int N,K,L;
	cin>>N>>K>>L;
	UnionFind U(N),V(N);
	for(int i=0;i<K;i++){
		int a,b;
		cin>>a>>b;
		a--,b--;
		U.unionSet(a,b);
	}
	for(int i=0;i<L;i++){
		int a,b;
		cin>>a>>b;
		a--,b--;
		V.unionSet(a,b);
	}
	map<pint,int> pam;
	pint P[SIZE];
	for(int i=0;i<N;i++){
		P[i]=pint(U.root(i),V.root(i));
		pam[P[i]]++;
	}
	for(int i=0;i<N;i++){
		cout<<pam[P[i]]<<" ";
	}
	cout<<endl;
}

Measured memory_bytes: 15104
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int pasta[3]; FOR(i,0,3) cin >> pasta[i];
  int ju[2]; FOR(i,0,2) cin >> ju[i];
  int ans = 999999;
  FOR(i,0,3) {
    FOR(j,0,2) {
      ans = min(ans, pasta[i]+ju[j]-50);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3068
#include <stdio.h>
int main(){
    int a, b;
    scanf("%d %d", &a, &b);
    if(a>b && b!=1 || (a==1 && b!=1))
        printf("Alice\n");
    else if(b>a || (b==1 && a!=1))
        printf("Bob\n");
    else
        printf("Draw\n");
    return 0;
}


Measured memory_bytes: 128
/*******************************
 * written by Koki Riho
 * Rih0z https://github.com/Rih0z
 *******************************/

#include<iostream>
#include<map>
#include<vector>
#include<string>
#include<numeric>
#include<algorithm>
#include<cmath>
#include <cassert>
#include <functional>

#define DEBUG false

#define FOR(i , a, b) for(size_t i = a ; i < b ; i++ )
#define REP(i,b) FOR(i , 0 , b)
#define RFOR(i,a,b) for(size_t i = a-1 ; i >= b ; i--)
#define RREP(i,a) RFOR(i,a,0)



typedef long long ll;
using namespace std;

int scanInt(void);
string scanString(void);

void scanLlArr(ll *a , int n);
void scanCharArr(char *string);

void printInt(int p);
void printLlArr(ll *a);
void printCharArr(char *string);


void perSum(ll *a , ll *sum ,int n);

/*************Global variable  **************/
int N,K ;
char str[26];
int A[200000] ;
int c[200000];
std::map<char,int> M ;
/*******************************/

int main(){
  if (DEBUG){
    std::printf("******debug mode********\n");
  }
  cin >> N >> K;
 REP(i,N){
   int a ; 
  cin >> a; 
  c[a-1]++;
 } 
 sort(c,c+N);
 int ans = 0 ;
 REP(i,N-K){
   ans += c[i] ; 
 }
 cout << ans << endl ; 
 return 0 ;
}


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

const int mod = 1000000007;

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

long long nCr(long long n, long long r){
    long long x = 1, y = 1;

    for(int i = 0; i < r; i++){
        x = x * (n - i) % mod;
        y = y * (i + 1) % mod;
    }
  
    return x*powmod(y,mod-2)%mod;
}

int main()
{
    long long n, a, b;
    cin >> n >> a >> b;
    long long ans = powmod(2, n) - 1 - nCr(n, a) - nCr(n, b);

    cout << (ans % mod + mod) % mod << endl;
    return 0;
}


Measured memory_bytes: 3596
#=
D:
- Julia version:  0.5.2
- Author: abap
- Date: 2019-11-24
=#
parseInt(x) = parse(Int,x)
parseMap(x::Array{SubString{String}, 1}) = map(parseInt, x)
function  main()
N = parse(readline())
renga = parseMap(split(readline()))

count = 0
w = 1
for i in 1:N
	if renga[i] != w
		count += 1
	else
		w += 1
	end
end

if w == 1
   println("-1")
else
   println(count)
end
end
main()

Measured memory_bytes: 169364
// 問題の URL を書いておく
// 

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <numeric>
using namespace std;

//#define ENABLE_PRINT

template<typename T>
T Input()
{
    T v;
    cin >> v;
    return v;
}

template<typename T>
vector<T> InputVector(int n)
{
    vector<T> v(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    return v;
}

template<typename T>
void InputArray(T* begin, int n)
{
    for(int i = 0; i < n; ++i)
    {
        cin >> begin[i];
    }
}

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

int main(int argc, const char* argv[])
{
    int k;
    cin >> k;

    string s;
    cin >> s;

    if(s.size() <= k)
    {
        cout << s << endl;
    }
    else
    {
        cout << s.substr(0, k) << "..." << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const ceil=(a)=>{return Math.ceil(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};const gcd=(x,y)=>{while(y){[x,y]=[y,x%y]}return x};const sum=(arr)=>{return arr.reduce((a,b)=>a+b);};const isPrime=(n:number):boolean=>{if(n<2)return false;const suq=Math.sqrt(n);for(let i=2;i<=suq;i++){if(n%i==0){return false;}}return true;};
const main=()=>{
  let [mh,mw]=tnn(2),map=new Array(mh),save=new Array(mh),cnt=0
  let start=[0,0]
  let dh=[0,0,-1,1]
  let dw=[1,-1,0,0]
  for(let i=0;i<mh;i++){
    map[i]=ts().split('')
    save[i]=new Array(mw)
    save[i].fill(-1)
    for(let j=0;j<mw;j++){
      if(map[i][j]=='#')cnt++
    }
  }
  let queue=[[start[0],start[1],2]],max=0
  save[start[0]][start[1]]=1
  while(queue.length>0){
    let [h,w,c]=queue.shift()
    if(h==mh-1&&w==mw-1){
      to(mh*mw-c-cnt+1)
      return
    }
    for(let i=0;i<4;i++){
      if(h+dh[i]<0 || h+dh[i]>=mh || w+dw[i]<0 || w+dw[i]>=mw || map[h+dh[i]][w+dw[i]]=='#')continue
      if(save[h+dh[i]][w+dw[i]]==-1&&map[h+dh[i]][w+dw[i]]=='.'){
        queue.push([h+dh[i], w+dw[i], c+1])
        save[h+dh[i]][w+dw[i]]=c
      }
    }
  }
  to(-1)
}
main()


Measured memory_bytes: 7628
#include<stdio.h>
int d[10]={0};

int han(int k){
  int a;
  while(k>0){
    a=k%10;
    if(d[a]==1) return 0;
    k/=10;
  }
  return 1;
}

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

  for(int j=n;;j++){
		if(han(j)==1){ 
			printf("%d",j);
			return 0;
		}
	}
}

Measured memory_bytes: 128
#include <cstdio>
#include <cctype>
inline bool get() {
	char ch = getchar();
	while(isspace(ch)) ch = getchar();
	return ch == '#';
}
bool a[510][510], b[510][510];
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i ++ ) {
		for(int j = 1; j <= m; j ++ ) {
			a[i][j] = b[i][j] = get();
		}
	}
	for(int i = 1; i <= n; i ++ ) a[i][1] = b[i][m] = 1;
	for(int i = 2; i < n; i += 2 ) for(int j = 2; j < m; j ++ ) a[i][j] = 1;
	for(int i = 3; i < n; i += 2 ) for(int j = 2; j < m; j ++ ) b[i][j] = 1;
	for(int i = 1; i <= n; i ++ ) {
		for(int j = 1; j <= m; j ++ ) putchar(a[i][j] ? '#' : '.');
		puts("");
	}
	puts("");
	for(int i = 1; i <= n; i ++ ) {
		for(int j = 1; j <= m; j ++ ) putchar(b[i][j] ? '#' : '.');
		puts("");
	}
}


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

  int main() {
    long long X;
    cin >> X;
    long long ans= 0;
    long long ANZ = 100;
    while(ANZ < X){
      ANZ = ANZ * 1.01;
      ans ++;
    }
      cout << ans <<endl;
    }
    

    

Measured memory_bytes: 3640
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
# from copy import deepcopy, copy

import queue
from collections import deque


def main():
    node_num, edge_num = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(edge_num)]

    graph_data = defaultdict(set)
    jisuu_list = [0 for i in range(node_num + 1)]
    for i in range(edge_num):
        a, b = data[i]
        graph_data[a].add(b)
        jisuu_list[b] += 1


    now_set = set()
    next_set = set()
    for i in range(1, node_num + 1):
        if jisuu_list[i] == 0:
            now_set.add(i)

    while len(now_set) > 0:
        for now_node in now_set:
            for next_node in graph_data[now_node]:
                jisuu_list[next_node] -= 1
                if jisuu_list[next_node] == 0:
                    next_set.add(next_node)
        now_set = next_set
        next_set = set()

    if max(jisuu_list) == 0:
        print(-1)
        sys.exit()

    ans = []
    dist = 10 ** 10
    for i in range(1, node_num + 1):
        if jisuu_list[i] == 0:
            continue

        parent_node = [0 for i in range(node_num + 1)]
        now_set = set()
        next_set = set()
        now_set.add(i)
        dist_kari = 0
        fin_flg = 0
        while len(now_set) > 0:
            dist_kari += 1
            # print(now_set, graph_data, fin_flg, parent_node)
            for now_node in now_set:
                for next_node in graph_data[now_node]:
                    # print('uuu', next_node)
                    if next_node == i:
                        parent_node[next_node] = now_node
                        fin_flg = 1
                        break
                    if jisuu_list[next_node] == 0:
                        continue
                    if parent_node[next_node] == 0:
                        parent_node[next_node] = now_node
                        next_set.add(next_node)
                if fin_flg:
                    break
            if fin_flg:
                break
            now_set = next_set
            next_set = set()

        if dist_kari < dist and fin_flg:
            dist = dist_kari
            ans = []
            now_node = parent_node[i]
            ans.append(i)
            # print(parent_node)
            while now_node != i:
                ans.append(now_node)
                now_node = parent_node[now_node]

    print(len(ans))
    for ele in ans:
        print(ele)







if __name__ == '__main__':
    main()

Measured memory_bytes: 50388
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    string s; cin >> s;
    int si = SIZE(s);
    char keep = s[0];
    int ans = 0;
    rng(i,1,si){
        if(s[i] != keep) ans++;
        keep = s[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main () {
	int h1, m1, h2, m2, k;
	scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
	
	int time1 = (h1 * 60) + m1;
	int time2 = (h2 * 60) + m2;
	
	printf("%d", time2 - time1 - k);
	return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int d, t, s;
  cin >> d >> t >> s;
  if (s * t >= d) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

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

    sort(a.begin(), a.end());

    int r = 0;
    for (int i = 0; i < n; i++) {
        if (x < a[i]) goto exit;
        x -= a[i];
        r++;
    }
    if (x > 0) r--;

exit:
    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>





const int N=1e5+10;
ll n,c,res,x[N],v[N],mx[N],s[4][N];



void f()
{
	s[1][0]=0;
	for(int i=1;i<=n;i++)
	{
		s[1][i]=s[1][i-1]+v[i];
	}
	s[2][n+1]=0;
	mx[n+1]=0;
	for(int i=n;i>=1;i--)
	{
		s[2][i]=s[2][i+1]+v[i];
		mx[i]=max(s[2][i]-(c-x[i]),mx[i+1]);
	}
	for(int i=0;i<=n;i++)
	{
		res=max(res,s[1][i]-(2*x[i])+mx[i+1]);
	}
}




void solve()
{
	cin>>n>>c;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i]>>v[i];
	}
	res=0;
	f();
	for(int i=1;i<=n;i++)x[i]=c-x[i];
	reverse(x+1,x+n+1);
	reverse(v+1,v+n+1);
	f();
	cout<<res<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>

int main(){
    std::string s;

    std::string front, end;
    int ctx = 0;

    int q, t, f;
    std::string c;

    std::cin >> s >> q;

    for(int i = 0; i < q; i++){
        std::cin >> t;
        if(t == 1){
            ctx++;
        }else{
            std::cin >> f >> c;
            if(f == 1){
                if(ctx % 2 == 0){
                    front.insert(0, c);
                }else{
                    end.append(c, 0, 1);
                }
            }else{
                if(ctx % 2 == 0){
                    end.append(c,0, 1);
                }else{
                    front.insert(0, c);
                }
            }
        }
    }

    if(ctx % 2 == 0){
        s = front + s + end;
    }else{
        std::reverse(front.begin(), front.end());
        std::reverse(end.begin(), end.end());
        std::reverse(s.begin(), s.end());
        s = end + s + front;
    }
    std::cout << s << std::endl;

    return 0;
}


Measured memory_bytes: 1348
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
54 65
)");
#define cin input
#endif

int main()
{
	int a, b;
	cin >> a >> b;

	cout << (b-a-1)*(b-a)/2-a << endl;
}

Measured memory_bytes: 256
# Problem: https://atcoder.jp/contests/abc088/tasks/abc088_c
# Python 1st Try

import sys
# from collections import defaultdict
# import heapq,copy
import pprint as pp
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
yes = "Yes"
no = "No"


def solver(c_grid):
    result = no
    a_list=[0, c_grid[1][0] - c_grid[0][0], c_grid[2][0] - c_grid[0][0]]
    b_list=[c_grid[0][0], c_grid[0][1], c_grid[0][2]]
    if (c_grid[1][1] == a_list[1] + b_list[1]) and \
        (c_grid[1][2] == a_list[1] + b_list[2]) and \
            ( c_grid[2][1] == a_list[2] + b_list[1]) and \
                ( c_grid[2][2] == a_list[2] + b_list[2]):
                    result = yes
    return result


if __name__ == "__main__":
    c_grid = list()
    for _ in range(3):
        c_grid.append(LI())
    # print("{}".format(c_grid))
    print("{}".format(solver(c_grid)))


Measured memory_bytes: 9832
def prime_table(n):
  list = [True for _ in xrange(n + 1)]
  i = 2
  while i * i <= n:
    if list[i]:
      j = i + i
      while j <= n:
        list[j] = False
        j += i
    i += 1

  table = [i for i in xrange(n + 1) if list[i] and i >= 2]
  return table

table = prime_table(105000)
while True:
    n = int(raw_input())
    if n == 0:
        break
    print sum(table[:n])

Measured memory_bytes: 5412
#include<stdio.h>
int main()
{
	int r, g[2], b, sum;
	scanf("%d %d %d",&r,&g[1],&b);
	if (g[1] % 2 == 0) g[2]=0;
	else g[2]=2;
	sum = g[2] + b;
	if (sum % 4 == 0) printf("YES");
	else printf ("NO");
	return 0;
}

Measured memory_bytes: 128
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {

    /////////////////////
    // Write code below /
    /////////////////////
    int height, width;
    cin >> height >> width;
    vector<string> a(height);
    for (int i = 0; i < height; i++) {
        cin >> a.at(i);
    }
    
    // 黒色のマスがあるrowとcolumnを記録する
    vector<bool> rows(height, false);
    vector<bool> columns(width, false);
    
    for (int row_i = 0; row_i < height; row_i++) {
        for (int column_i = 0; column_i < width; column_i++) {
            if (a.at(row_i).at(column_i) == '#') {
                rows.at(row_i) = true;
                columns.at(column_i) = true;
            }
        }
    }
    
    for (int row_i = 0; row_i < height; row_i++) {
        if (rows.at(row_i)) {
            for (int column_i = 0; column_i < width; column_i++) {
                if (columns.at(column_i)) {
                    cout << a.at(row_i).at(column_i);
                }
            }
            cout << endl;
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 256
//Can you solve this?

#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
using ll = long long;
#define range(a) (a).begin(),(a).end()


int main (){
    int N, M, C, Ans=0; cin >> N >> M >> C;
    vector<int> B(M);
    vector<vector<int>> A(N, vector<int>(M));
    rep(i,0,M)cin >> B[i];
    rep(i,0,N){
        rep(j,0,M){
            cin >> A[i][j];
        }
    }
    rep(i,0,N){
        int sum = C;
        rep(j,0,M){
            sum += B[j]*A[i][j];
        }
        if(sum > 0)Ans++;
    }    
    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 256
gets
Cs = gets.chomp

windex = []
rindex = []
Cs.length.times.each do |i|
  if Cs[i] == "W"
    windex.push(i)
  else
    rindex.push(i)
  end
end
rindex = rindex.reverse

count = [windex.size, rindex.size].min
count.times.each do |i|
  # puts "w#{windex[i]} r#{rindex[i]}"
  if windex[i] > rindex[i]
    puts i
    exit
  end
end

puts count


Measured memory_bytes: 17888
n, k = map(int, input().split())

base = 1 / n
ans = 0
for i in range(1, n+1):
    if i >= k:
        ans += base
        continue

    cnt = 0
    while 1:
        i *= 2
        cnt += 1
        if i >= k:
            break

    ans += base * pow(0.5, cnt)

print(ans)

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

int main(){
    ll x;
  	cin >> x;
    for(int i = -200; i <= 200;i++){
        for(int j = -200; j <= 200;j++){
            ll s = pow(i,5);
            ll t = pow(j,5);
            if((s - t) == x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 4020
//
//  main.cpp
//  ABC082
//
//  Created by Hoshikawa Hiroaki on 2019/03/16.
//  Copyright © 2019年 Hoshikawa Hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int a,b;
    cin >> a>>b;
    if((a+b)%2==0){
      cout<<(a+b)/2<<endl;
    }else{
      cout<<(a+b)/2+1<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
import math

n, m = map(int,input().split())
s = input()
t = input()

x = math.gcd(n,m)
ans = n*m//x
n = n//x
m = m//x

for i in range(x):
    if s[n*i] != t[m*i]:
        print(-1)
        exit()

print(ans)

Measured memory_bytes: 9316
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

combination table(1e6);

int main(){
    int N;
    cin >> N;
    lint C[N];
    cins(C, C + N);
    sort(C, C + N, greater<>());
    lint ans = 0;
    for(int i = 0; i < N; i++){
        if(i == 0){
            ans += C[i] % mod * power(2, N - 1, mod) % mod;
        }else{
            ans += (i + 2) % mod * C[i] % mod * power(2, N - 2, mod) % mod;
        }
        ans %= mod;
    }
    cout << ans * power(2, N, mod) % mod << endl;
}



Measured memory_bytes: 17408
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static int mod = 1000000007;

    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = new int[M];
        int sumA = N;
        for(int i=0;i<M;i++){
            A[i] = sc.nextInt();
            sumA -= A[i];
        }

        if(sumA < 0){
            sumA = -1;
        }

        System.out.println(sumA);

    }

}









Measured memory_bytes: 46168
N = int(input())
X = input()
ans = [1 for _ in range(N)]

if N == 1:
  if X[0] == '1':
    print(0)
    exit()
  else:
    print(1)
    exit()


l = X.count('1')

if l == 0:
  for _ in range(N):
    print(1)
  exit()
if l == 1:
  if X[-1] == '1':
    for _ in range(N-1):
      ans[_] = 2
  else:
    ans[-1] = 2 
  for k in range(N):
    if X[k] =='1':
      ans[k] = 0 
  for _ in range(N):
    print(ans[_])
  exit()
 
 
intN = int(X, 2)
N1 = intN %(l-1)
N0 = intN %(l+1)


start = []
s1 = 1
s0 = 1
for k in range(N-1, -1, -1):
  if X[k] == '1':      
    ia = (N1 - s1)%(l-1)
  else:
    ia = (N0 + s0)%(l+1)
  start.append(ia)
  s1 = s1*2%(l-1)
  s0 = s0*2%(l+1)
start = start[::-1]



"""
poplist = [0 for _ in range(l+1)]
t = 1
while t < l + 2:
  for k in range(t, l+1, 2*t):
    for j in range(t):
      if k+j>l:
        break
      poplist[k+j] += 1
  t *= 2
"""
ml = len(bin(l+1))-2
poplist = [[] for _ in range(ml)]
poplist[0] = [0,1]
for k in range(1, ml):
  for m in range(k):
    poplist[k] += poplist[m]
  for m in range(len(poplist[k])):
    poplist[k][m] += 1
newpoplist = []
for _ in range(len(poplist)):
  newpoplist += poplist[_] 
poplist = newpoplist

for k in range(len(start)):
  for count in range(10*5):
    if start[k] == 0:
      ans[k] += count
      break
    else:
      start[k] = start[k] % poplist[start[k]]
 
for k in range(N):
  print(ans[k])

Measured memory_bytes: 20564
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

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

    double r = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            int dx = x[i] - x[j];
            int dy = y[i] - y[j];
            double d = sqrt(dx * dx + dy * dy);
            r = max(r, d);
            for (int k = 0; k < j; k++) {
                int l[3] = { i, j, k };
                int b = 0;
                int x0, y0, x1, y1, ip;
                for (int h = 0; h < 3; h++) {
                    x0 = x[l[1]] - x[l[0]];
                    y0 = y[l[1]] - y[l[0]];
                    x1 = x[l[2]] - x[l[0]];
                    y1 = y[l[2]] - y[l[0]];
                    ip = x0 * x1 + y0 * y1;
                    if (ip <= 0) {
                        b = 1;
                        break;
                    }
                    swap(l[1], l[2]);
                    swap(l[0], l[2]);
                }
                if (b) continue;
                double sn = sqrt(1 - (double)ip * ip / ((double)(x0 * x0 + y0 * y0) * (x1 * x1 + y1 * y1)));
                r = max(r, d / sn);
            }
        }
    }
    printf("%.12f\n", r * 0.5);

    return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int h,w,n; cin>>h>>w>>n;
	vector<vector<short>>ans(h,vector<short>(w));
	for(int i=1,y=0,x=0;i<=n;++i){
		int a; cin>>a;
		while(a){
			if(x==w)x=0,++y;
			ans.at(y).at(x)=i;
			--a,++x;
		}
	}
	for(int y=0;y<h;++y){
		if(y&1)for(int x=w-1;x>=0;--x){
			cout<<ans.at(y).at(x);
			if(x!=0)cout<<" "s;
		}else for(int x=0;x<w;++x){
			cout<<ans.at(y).at(x);
			if(x!=w-1)cout<<" "s;
		}
		cout<<"\n"s;
	}
}

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

template<typename T>
T gcd(T a, T b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

template<typename T>
T lcm(T a, T b) {
  return a * b / gcd(a, b);
}

void Main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;

  long long g = gcd(c, d);
  long long l = c / g * d;
  long long bb = b - b / c - b / d + b / l;
  a--;
  long long aa = a - a / c - a / d + a / l;
  cout << bb - aa << endl;
}

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


Measured memory_bytes: 256