akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int x=sc.nextInt();
    int ans=1;
    int l[]=new int[n];
    
    for(int i=0;i<n;i++){
      l[i]=sc.nextInt();
    }
    int d=0;
    for(int i=0;i<n;i++){
      d=d+l[i];
      if(d<=x){
        ans++;
      }
      else{
        break;
      }
    }
    System.out.println(ans);
  }
}


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

int main() {
  int n,a,b;cin>>n>>a>>b;
  int x=min(a,b),y=max(a+b-n,0);
  cout<<x<<" "<<y<<endl;
}

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

void solve(int n){
  bool ans = (n == 3) or (n == 5) or (n == 7);
  
  cout<<(ans ? "YES" : "NO")<<endl;
}

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

  solve(n);

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{  
 public static void main(String args[]){  
   Scanner sc=new Scanner(System.in);
   String s=sc.nextLine();
   String s1="ABC";
   if(s.equals(s1))
      System.out.println("ARC");
   else
      System.out.println("ABC");
      
      }
      
      }

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i > 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define PI 3.14159265358979

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll MOD = 1000000007;


const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    ll N, M;
    cin >> N >> M;
    mint ans = 0;
    FOR(i, M, N+2) {
        ll ma = (i * (N-i+1 + N)) / 2;
        ll mi = (i * (i-1)) / 2;
        ans += ma - mi+1;
    }
    PRINT(ans);
    return 0;
}


Measured memory_bytes: 3564
N,C = list(map(int,input().split()))

P = [[] for i in range(C)]

for i in range(N):
    s,t,c = list(map(int,input().split()))
    P[c-1].append([s,"S"])
    P[c-1].append([t,"T"])

P = [sorted(sorted(P[i],key=lambda x:x[1]),key=lambda x: x[0]) for i in range(C)]
#print(P)
P2 = []

for i in range(C):
    for j in range(len(P[i])):
        if P[i][j][1]=="T":
            if j!=0:
                if P[i][j][0]!=P[i][j-1][0]:
                    P2.append(P[i][j])
            else:
                P2.append(P[i][j])
        else:
            if j!=len(P[i])-1:
                if P[i][j][0]!=P[i][j+1][0]:
                    P2.append([P[i][j][0]-0.5,P[i][j][1]])
            else:
                P2.append([P[i][j][0]-0.5,P[i][j][1]])

P = P2
P = sorted(P,key=lambda x:x[0])

count=0
max_count=0
s_buf = 0
t_buf = 0

prev = -1
for i in range(len(P)):
    if prev!=P[i][0]:
        prev=P[i][0]
        count+=s_buf-t_buf
        s_buf=0
        t_buf=0
        max_count=max(count,max_count)
    if P[i][1]=="S":
        s_buf+=1
    else:
        t_buf+=1
#print(P)
count+=s_buf-t_buf
max_count=max(count,max_count)

print(max_count)

Measured memory_bytes: 48636
n,k = map(int,input().split())
import math

ans = 0
for i in range(1,n+1):
  if i >= k :
    ans += 1/n
  else:
    x = math.ceil( math.log2(k/i) )
    ans += 1/n * (1/2) ** x  
 
print(ans)

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

ll n, m;

ll ans;

int main(void) {
  // Here your code !
  scanf("%lld %lld", &n, &m);

  ans = 1LL;

  for (ll i = 1LL; i * i <= m; ++i) {
    if (m % i > 0) continue;

    ll other = m / i;

    if (i == other) {
      if (other >= n) ans = max(ans, i);
    } else {
      if (other >= n) ans = max(ans, i);
      if (i >= n) ans = max(ans, other);
    }
  }

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

  return 0;
}


Measured memory_bytes: 256
N, K = list(map(int,input().strip().split(' ')))
A = list(map(int,input().strip().split(' ')))
tmp = N-K
ans = 1
flg = 0
while tmp >= 0:
    if tmp == 0:
        print(ans)
        flg = 1
        break
    tmp = tmp - (K-1)
    ans = ans + 1

if flg ==0:
    print(ans)

Measured memory_bytes: 14008
import java.util.Scanner;

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

        Scanner input = new Scanner(System.in);
        int numberOf = input.nextInt();
        int numberAtATime = input.nextInt();
        double timeToMake = input.nextInt();
        double timeToMake2;
        double timeToMake3;


        timeToMake3 = timeToMake * Math.floor(numberOf / numberAtATime) + timeToMake;
        if (numberOf % numberAtATime == 0)
        {
            timeToMake2 = timeToMake * Math.floor(numberOf / numberAtATime);
            System.out.print((int)timeToMake2);
        }
        else {
            System.out.println((int)timeToMake3);
        }
    }
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    set<int> s;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        s.insert(a);
    }

    if(s.size() == n)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

void solve(){
	int a, b;
	scanf("%d%d", &a, &b);
	if (a > b) {
		swap(a, b);
	}
	if (a < b - 1) {
		printf("0\n");
		return;
	}
	ll ans = 1ll;
	REPN(i, 1, a) {
		ans = (ans * i) % MOD;
	}
	REPN(i, 1, b) {
		ans = (ans * i) % MOD;
	}
	if (a == b) {
		ans = (ans * 2) % MOD;
	}
	printf("%lld\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, r, s, p, ans = 0;
  scanf("%lld%lld%lld%lld%lld", &n, &k, &r, &s, &p);
  char t[n + 10];
  scanf("%s", t);
  for(i = 0; i < n; ++i) {
    if(i < k || t[i - k] != t[i]) {
      if(t[i] == 'r') ans += p;
      else if(t[i] == 's') ans += r;
      else ans += s;
    } else t[i] = 'a';
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

ans = 0
n = inp[0]
s = n.to_s
s.size.times do |j|
  i = s.size - j - 1
  c = s[i]
  if(i - 1<0)
    if(j.even?)
      ans += n - 10**j+1
    else
      ans += 9*10**(j-1)
    end
  else
    if(j.odd?)
      ans += 9*10**(j-1)
    end
  end
end
p ans

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <stdio.h>
#include <utility>
#include <map>
#include <set>
using namespace std;

#define LL long long;
int a, p;


int main() {

	cin >> a >> p;

	cout << (a * 3 + p) / 2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define getMat(x, n, m, val) vector<vector<ll>> x(n, vector<ll> (m, val))
#define setp fixed<<setprecision
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll M=1000000000+7;
 
ll power(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

ll co=0;

void dfs(vector<ll>v[], bool vis[], ll src){
    vis[src]=1;
    co++;
    for(ll to:v[src]){
        if(!vis[to])dfs(v,vis,to);
    }
}

int main(){
    fastio;
    ll n,m;
    cin>>n>>m;
    vector<ll>v[n+1];
    for(ll i=0;i<m;i++){
        ll a,b;
        cin>>a>>b;
        // ll f=0;
        // for(ll to:v[a]){
        //     if(to==b){
        //         f=1;
        //         break;
        //     }
        // }
        // if(f)continue;
        v[a].pb(b);
        v[b].pb(a);
    }
    bool vis[n+1]={0};
    ll ans=-1;
    for(ll i=1;i<=n;i++){
        if(!vis[i]){
            co=0;
            dfs(v,vis,i);
            ans=max(ans,co);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 24068
//AC済 バチャ用再提出
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct SegmentTree {
private:
    int n;
    vector<int> node;
 
public:
    SegmentTree(vector<int> v) {
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = (node[2*i+1] + node[2*i+2]);
    }
 
    void add(int x, int val) {
        x += (n - 1);
        node[x] += val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = (node[2*x+1] + node[2*x+2]);
        }
    }
    // hannkaikukann 
    int getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return node[k];
 
        int vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        int vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return (vl + vr);
    }
};


#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    ll n;
    cin >> n;
    int a[100050];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    if(n == 1){
        cout << a[1] << endl;
        return 0;
    }
    ll ok = 1;
    ll ng = 1000000005;
    while(ng - ok > 1){
        ll mid = (ok + ng) / 2;
        int b[200050];
        for(int i = 1; i <= n; i++){
            if(a[i] >= mid){
                b[i] = 1;
            } else {
                b[i] = -1;
            }
        }
        int sum = 100000;
        vector<int> v(200050);
        SegmentTree seg(v);
        ll inversion = 0;
        bool checker = false;
        seg.add(100000, 1);
        for(int i = 1; i <= n; i++){
            sum += b[i];
            inversion += seg.getsum(0, sum + 1);
            //cout << mid << " " << i << " " << seg.getsum(0, sum + 1) << " " << inversion << endl;
            seg.add(sum, 1);
            if(inversion >= (n * (n + 1) / 4)){
                checker = true;
                break;
            }
        }
        if(checker){
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)
char ini[256];

int main(void)
{
    ll m[10];
    ll n;
    string name;
    REP(i, 255) ini[i] = 5;
    ini['M'] = 0;
    ini['A'] = 1;
    ini['R'] = 2;
    ini['C'] = 3;
    ini['H'] = 4;
    REP(i, 7) m[i] = 0;

    cin >> n;
    REP(i, n) {
        cin >> name;
        m[ini[name[0]]] ++;
    }
    ll cnt = 0;
    for(ll i = 0; i < 3; i++) {
        for(ll j = i + 1; j < 4; j++) {
            for(ll k = j + 1; k < 5; k++) {
                cnt += m[i]*m[j]*m[k];
 //               cout << i << ":" << j << ":" << k << ":" << cnt << endl;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
/**
 * @author derrick20
 */
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = sc.nextInt();
        HashMap<String, Integer> seen = new HashMap<>();
        long total = 0;
        for (int i = 0; i < N; i++) {
            String s = sc.next();
            int[] cts = new int[26];
            for (char c : s.toCharArray()) {
                cts[c - 'a']++;
            }
            StringBuilder hash = new StringBuilder();
            for (int val : cts) {
                hash.append(val + "_");
            }
            String key = hash.toString();
            if (seen.containsKey(key)) {
                total += seen.get(key);
                seen.put(key, seen.get(key) + 1);
            }
            else {
                seen.put(key, 1);
            }
        }
        out.println(total);
        out.close();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        FastScanner(FileReader s) {
            br = new BufferedReader(s);
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        String nextLine() throws IOException { return br.readLine(); }

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

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

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

Measured memory_bytes: 171804
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;


llint n, m;
llint a[100005], b[100005];
vector<llint> G[100005];
vector<P> vec;

struct UnionFind{
	int size;
	vector<int> parent;
	vector<llint> gain, need;
	
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		gain.resize(size+1);
		need.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++){
			parent[i] = i;
			need[i] = a[i];
			gain[i] = b[i];
		}
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
		gain[root_j] += gain[root_i];
	}
};

UnionFind uf(100005);


int main(void)
{
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> b[i];
		a[i] -= b[i];
		a[i] = max(a[i], 0LL);
		vec.push_back(P(a[i], i));
	}
	sort(vec.begin(), vec.end());
	
	llint u, v;
	for(int i = 1; i <= m; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	uf.init();
	
	for(int i = 0; i < vec.size(); i++){
		int v = vec[i].second;
		for(int j = 0; j < G[v].size(); j++){
			int u = G[v][j];
			if(a[u] > a[v] || uf.same(u, v)) continue;
			u = uf.root(u);
			llint dif = max(0LL, a[v] - (uf.need[u] + uf.gain[u]));
			llint tmp = min(uf.need[u] + dif, uf.need[uf.root(v)]);
			uf.unite(u, v);
			u = uf.root(u);
			uf.need[u] = tmp;
		}
	}
	int r = uf.root(1);
	cout << uf.need[r] + uf.gain[r] << endl;
	
	return 0;
}

Measured memory_bytes: 11376
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;
const int MOD = 1000000007;
const ll INF = 1LL << 60;

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

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

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

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


int main(int argc, char**argv){
    string s;
    cin >> s;
    if (s[0] >= s[1] && s[0] >= s[2]) cout << s[0] << s[0] << s[0] << endl;
    else cout << s[0] - '0' + 1 << s[0] - '0' + 1 << s[0] - '0' + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using std::swap;

// priceをキーに降順でソート
//sort(fruits.begin(), fruits.end(),
//     [](const fruit& x, const fruit& y) { return x.price > y.price;});

/*
int main() {
    int A, B;
    std::cin >> A >> B;
    std::cout << max(A-2*B, 0);

    return 0;
}
 */

/*
int main(){
    int N;
    std::cin >> N;
    int a[N];
    int heal=0;
    for(int i=0; i<N; i++){
        std::cin >> a[i];
    }
    for(int i=0; i<N; i++){
        for(int j=0; j<i; j++){
            heal+= a[i]*a[j];
        }
    }
    std::cout << heal << std::endl;
    return 0;
}
 */

int main(){
    int N;
    string S;
    std::cin >> N >> S;
    int count=1;
    for(int i=1; i<N; i++){
        if(S[i-1]!=S[i]){
            count++;
        }
    }
    std::cout << count << std::endl;
    return 0;
}



Measured memory_bytes: 512
#include<iostream>

#include<cstdlib>
#include<algorithm>
#include <math.h>
#include <string> 
#include<vector>
#include<fstream>

using namespace std;

int main()
{
	int n,m,c,temp,count,ans=0;
	cin>> n >> m >>c;
	
	
	int B[m];
	for(int i=0;i<m;i++)
	{
		cin>>temp;
		B[i] = temp;
	}
	
	for(int i=0;i<n;i++)
	{
		count=0;
		
		for(int j=0;j<m;j++)
		{
			cin >> temp;
			count += temp * B[j]; 
		}
		count = count + c;
		
		if(count>0)
		{
			ans = ans + 1;
		}
	}
	
	cout << ans;
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

from collections import deque
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, W = na()
weight = [0] * 110
value = [0] * 110
for i in range(N):
    v, w = na()
    weight[i], value[i] = w, v
dp = [[0] * 10010 for _ in range(110)]
for i in range(N):
    for w in range(W+1):
        if w >= weight[i]:
            dp[i+1][w] = max(dp[i+1][w-weight[i]] + value[i], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]
print(dp[N][W])



Measured memory_bytes: 46088
N,A,B,C,D = map(int,input().split())
s = input() + '##'
ans = True

if C > D:
    if '...' not in s[B-2:D+1]: ans = False
if ans:
    if '##' in s[B:D]:    ans = False
    if '##' in s[A:C]:    ans = False

if ans: print('Yes')
else:   print('No')

Measured memory_bytes: 3572
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = sum(B)

for i in range(N, -1, -1):
  if i == N:
    if B[i-1] <= A[i]:
      B[i-1] = 0
    else:
      B[i-1] -= A[i]

  elif 1 <= i <= N-1:
    if B[i] <= A[i]:
      A[i] -= B[i]      
      B[i] = 0
    else:
      B[i] -= A[i]
      A[i] = 0
    if B[i-1] <= A[i]:
      A[i] -= B[i-1]
      B[i-1] = 0
    else:
      B[i-1] -= A[i]
      A[i] = 0

  elif i == 0:
    if B[i] <= A[i]:
      A[i] -= B[i]
      B[i] = 0
    else:
      B[i] -= A[i]
      A[i] = 0

print(ans-sum(B))

Measured memory_bytes: 82148
#include <iostream>
#include <cstring>
using namespace std;
#define REP(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) REP(i, 0, n)
int memo[11][1024][300];
int func(int k, int used_n, int n, int s, int goal)
{
	if (k == n) return s == goal;

	int& res = memo[k][used_n][s];
	if (res >= 0) return res;
	res = 0;
	rep(j, 10) if (!(used_n & (1<<j))) {
		res += func(k+1, used_n+(1<<j), n, s+(k+1)*j, goal);
	}
	return res;
}
int main()
{
	ios_base::sync_with_stdio(0);
	int n, s;
	while (cin >> n >> s) {
		memset(memo, -1, sizeof(memo));
		int res = n > 10 ? 0 : func(0, 0, n, 0, s);
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            decimal N = decimal.Parse(Console.ReadLine());
            decimal[] iArray = Console.ReadLine().Split(' ').Select(i => decimal.Parse(i)).ToArray();
            List<decimal> sum = new List<decimal>();
            for(int d = 0; d < N; d++)
            {
                sum.Add(1/iArray[d]);
            }
            Console.WriteLine(1/sum.Sum());
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    vector<int> A(N); for (auto& a : A) cin >> a;
    long long m = 2, M = 2;
    for (int i = A.size()-1; i >= 0; i--) {
        M = M / A[i] * A[i] + A[i] - 1;
        m = (m + A[i] - 1) / A[i] * A[i];
        if (m > M) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << m << ' ' << M << endl;
    return 0;
}


Measured memory_bytes: 640
/*
cd "/Users/yuuki/Desktop/C++/Codes"
g++ -o run run.cpp
./run
*/


//11-5 チーズ
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<math.h>
#include<time.h>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<stack>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<random>
#include<cassert>
using namespace std;
#define LL long long
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while(true)

int H,W,N;
string s[1000];
pair<int, int> fact[10];
int dis[10][10];

int cost[1000][1000];

queue<pair<int,int>> que;
void move(int h, int w){
    if(h-1>=0 && s[h-1][w]!='X' && cost[h-1][w]>cost[h][w]+1){
        cost[h-1][w] = cost[h][w]+1;
        //move(h-1,w);
        que.push(make_pair(h-1,w));
    }
    if(h+1<H && s[h+1][w]!='X' && cost[h+1][w]>cost[h][w]+1){
        cost[h+1][w] = cost[h][w]+1;
        //move(h+1,w);
        que.push(make_pair(h+1,w));
    }
    if(w-1>=0 && s[h][w-1]!='X' && cost[h][w-1]>cost[h][w]+1){
        cost[h][w-1] = cost[h][w]+1;
        //move(h,w-1);
        que.push(make_pair(h,w-1));
    }
    if(w+1<W && s[h][w+1]!='X' && cost[h][w+1]>cost[h][w]+1){
        cost[h][w+1] = cost[h][w]+1;
        //move(h,w+1);
        que.push(make_pair(h,w+1));
    }
}

int max_health = 1;
bool fact_b[10];
LL ans = LL_MAX;
void cul(int health, int now, LL c){
    if(health == max_health) ans = min(ans,c);
    else{
        for(int i=1; i<=health && i<=N; i++){
            if(fact_b[i]==false){
                fact_b[i] = true;
                cul(health+i, i, c+dis[now][i]);
            }
        }
    }
}

int main(){
    cin >> H >> W >> N;
    for(int i=0; i<H; i++){
        cin >> s[i];
        for(int j=0; j<W; j++){
            if(s[i][j] == 'S') fact[0] = make_pair(i,j);
            else if(s[i][j] != 'X') fact[s[i][j]-'0'] = make_pair(i,j);
        }
    }

    for(int i=0; i<N-1 || i==0; i++){
        for(int j=0; j<H; j++){
            for(int k=0; k<W; k++){
                cost[j][k] = INT_MAX;
            }
        }
        cost[fact[i+1].first][fact[i+1].second] = 0;
        move(fact[i+1].first, fact[i+1].second);
        while(!que.empty()){
            move(que.front().first, que.front().second);
            que.pop();
        }
        for(int j=0; j<N; j++){
            dis[i+1][j+1] = cost[fact[j+1].first][fact[j+1].second];
            dis[j+1][i+1] = cost[fact[j+1].first][fact[j+1].second];
        }
        if(i == 0){
            dis[0][1] = cost[fact[0].first][fact[0].second];
            dis[1][0] = cost[fact[0].first][fact[0].second];
        }
        max_health += i+1;
    }
    if(N!=1) max_health += N;
    
    for(int i=0; i<N+1; i++){
        fact_b[i] = false;
    }
    fact_b[0] = true;
    cul(1,0,0);
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 7928
s = input()

while len(s) >= 5:
    if s[-5:] == 'dream':
        s = s[:-5]
        continue
    elif s[-7:] == 'dreamer':
        s = s[:-7]
        continue
    elif s[-5:] == 'erase':
        s = s[:-5]
        continue
    elif s[-6:] == 'eraser':
        s = s[:-6]
        continue
    else:
        break
if len(s):
    print('NO')
else:
    print('YES')


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >
#define vs vector<string>
#define vc vector<char>
#define vvc vector< vector<char> >

#define all(a) (a).begin(),(a).end()
using namespace std;

int main(){
	ll n; cin >> n;
	vl a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	sort(all(a));
	cout << a[n - 1] - a[0] << endl;
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
d = n // k
q = n % k

M = [0 for i in range(k)]
if not q == 0:
    for i in range(1, q+1):
        M[i] = d + 1
    for i in range(q+1, k):
        M[i] = d
    M[0] = d
else:
    for i in range(k):
        M[i] = d

cnt = 0
cnt += M[0] ** 3
if k % 2 == 0:
    cnt += M[k//2] ** 3

print(cnt)


Measured memory_bytes: 4680
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main(){
	int x, a, b;
	cin >> x >> a >> b;
	if (a + x < b) {
		cout << "dangerous";
	}
	else if (a >= b) {
		cout << "delicious";
	}
	else cout << "safe";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)

int main() {
  int n, left = 0, total = 0;
  cin >> n;
  vector<int> w(n);
  REP(i, n) {
    cin >> w[i];
    total += w[i];
  }
  int ans = total, sum = 0;
  REP(i , n) {
    sum += w[i];
    ans = min(ans, abs(sum * 2 - total));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <limits.h>
#include <assert.h>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define db double
#define ldb long double
#define MOD 1000000007
#define Fi first
#define Se second
#define INF INT_MAX
#define NINF INT_MIN
#define L_INF LLONG_MAX
#define L_NINF LLONG_MIN
#define gc getchar
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>

void fsscan(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

void scani(int &x)
{
    register int c = gc();x = 0;int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

ll gcd(ll a,ll b)
{
    if (a == 0)
        return b;
    return gcd(b%a, a);
}

int main()
{
    fsscan();
    
    ll k;
    ll n;
    cin>>k>>n;
    
    ll a[n];
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    
    ll mino  = INT_MAX;
    for(int i=0;i<n;i++) {
        if(i==0) {
            mino = min(mino,a[n-1] - a[i]);
            mino = min(mino, a[i] + k - a[i+1]);
        } else if(i==n-1) {
            mino = min(mino,a[i]-a[0]);
            mino = min(mino, k-a[i] + a[i-1]);
        } else {
            mino = min(mino, a[i] + k -a[i+1]);
            mino = min(mino, k-a[i] + a[i-1]);
        }
    }
    cout<<mino;
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int solvea(int a, int b){
  int x,y;
  if(a>=b){
    x = a;
    y = b;
  }else{
    x = b;
    y = a;
  }
// x > y
  if(x%y==0){
    printf("%d\n",y);
    return y;
  }
  solvea(y,x%y);
}

int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  int ans = solvea(a,b);
  //printf("%d\n", ans);
}



Measured memory_bytes: 2144
# -*- coding: utf-8 -*-
n = int(input())
h = [int(i) for i in input().split()]

def func(h):
    if len(h) == 0:
        return 0
    res = min(h)
    h = [i - min(h) for i in h]
    next_h = []
    flag = False
    tmp = 0
    for i in range(len(h)):
        if h[i] != 0 and not flag:
            flag = True
            tmp = i
        if h[i] == 0 and flag:
            next_h.append(h[tmp:i])
            flag = False
    if flag:
        next_h.append(h[tmp:len(h)])
    #print(h)
    #print(next_h)
    for i in range(len(next_h)):
        res += func(next_h[i])
    return res

print(func(h))


Measured memory_bytes: 3188
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String s[]=new String[n];
        for(int i=0;i<n;i++){
            s[i]=sc.next();
        }
        int m=sc.nextInt();
        String t[]=new String[m];
        for(int i=0;i<m;i++){
            t[i]=sc.next();
        }
        int ans[]=new int[n];
        
        for(int i=0;i<n;i++){
            ans[i]=0;
            for(int j=0;j<n;j++){
                if(s[i].equals(s[j])){
                    ans[i]++;
                }
            }
            for(int j=0;j<m;j++){
                if(s[i].equals(t[j])){
                    ans[i]--;
                }
            }
        }
        int max=ans[0];
        for(int i=0;i<n;i++){
            max=Math.max(ans[i],max);
        }
        if(max<=0) System.out.println(0);
        else System.out.println(max);
    }
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    int H[N];
    int judge[N];
    rep(i,N){
        H[i] = 0;
        judge[i] = 0;
    } 
    rep(i,N){
        cin >> H[i];
    }
    rep(i,M){
        int res1,res2;
        cin >> res1 >> res2;
        if(H[res1-1] <= H[res2-1]) judge[res1-1] += 1;
        if(H[res2-1] <= H[res1-1]) judge[res2-1] += 1;
    }
    int sum = 0;
    rep(i,N){
        if(judge[i] == 0) sum++;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 4432
def is_intersect(ax, ay, bx, by, cx, cy, dx, dy )
  tc = (ax-bx)*(cy-ay)+(ay-by)*(ax-cx)
  td = (ax-bx)*(dy-ay)+(ay-by)*(ax-dx)
  return tc * td < 0
end

STDIN.each_line do |s|
  x1, y1, x2, y2, x3, y3, xp, yp = s.chomp.split.map &:to_f
  ctx = ( x1 + x2 + x3 ) / 3.0
  cty = ( y1 + y2 + y3 ) / 3.0

  r = !is_intersect( x1, y1, x2, y2, ctx, cty, xp, yp ) \
      && !is_intersect( x2, y2, x3, y3, ctx, cty, xp, yp ) \
      && !is_intersect( x3, y3, x1, y1, ctx, cty, xp, yp )

  puts r ? "YES" : "NO"
end

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

int main(){
  int H, N;
  cin >> H >> N;
  int damage = 0;
  for(int i=0; i<N; i++){
    int A;
    cin >> A;
    damage+=A;
  }
  if(H<=damage) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n;
    ll A,B;
    ll p1=0,p2=0;
    cin >> n;
    priority_queue<ll> que;

    ll sumB=0;
    rep(i,n){
        cin >> A >> B;
        sumB -= B;
        que.push(A+B);
    }

    int cnt = 0;

    while(!que.empty()){
        if(cnt % 2 == 0){
            sumB += que.top();
        }
        que.pop();
        cnt++;
    }

    cout << sumB << endl;

    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<map>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main(){
	double a,b,c;
	int d,e;
	while(scanf("%lf",&c)!=EOF){
		a=c/9.8;
		b=(a*a*4.9+5)/5;
		d=(a*a*4.9+5)/5;
		if(b!=d)d++;
		printf("%d\n",d);
	}
}

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

int main() 
{
    int k ,a,b, flg = 0;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i % k == 0)
        {
            flg = 1;
            break;
        }
    }
    if(flg)
        cout<<"OK";
    else
        cout<<"NG";
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
	int n;
	cin>>n;
	string s;
	int x;

	vector<pair<pair<string,int>,int> > v;
	for(int i=1;i<=n;i++)
	{
		cin>>s>>x;

		v.pb(make_pair(make_pair(s,-1*x),i));
	}

	sort(all(v));

	for(int i=0;i<v.size();i++)
	cout<<v[i].second<<endl;
}

Measured memory_bytes: 256
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        sc.nextLine();
        List<Integer> list = IntStream.range(0, n).map(m -> sc.nextInt()).sorted().boxed().collect(Collectors.toList());
        System.out.println(list.subList(0, k).stream().mapToInt(i -> i).sum());
    }
}


Measured memory_bytes: 39552
import sys

input = sys.stdin.readline


def calc_prime_factors(n, count=False):
    """Trial division"""
    factors = []
    # factor: 2
    while n % 2 == 0:
        factors.append(2)
        n //= 2
    # factor: 3, 5, 7, 11, ...
    f = 3
    root_n = int(n ** 0.5) + 1
    while f <= root_n:
        if n % f == 0:
            factors.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        factors.append(n)
    return factors


def main():
    N = int(input())

    factors = calc_prime_factors(N)

    print("{}:".format(N), " ".join(map(str, factors)))


if __name__ == "__main__":
    main()



Measured memory_bytes: 5640
N=int(input())
if N<600:
  print(8)
elif N<800:
  print(7)
elif N<1000:
  print(6)
elif N<1200:
  print(5)
elif N<1400:
  print(4)
elif N<1600:
  print(3)
elif N<1800:
  print(2)
else:
  print(1)


Measured memory_bytes: 9164
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int n,m;
vector<int> graf[100010];
vector<int> grafNaopako[100010];
int uviru[100010];
queue<int> red;
int topoloski[100010];
int duzt=0;
bool marked[100010];
int vrednosti[100010];

int resi(int c)
{
	int sol=0;
	for(int i=0;i<grafNaopako[c].size();i++)
		sol=max(sol,vrednosti[grafNaopako[c][i]]+1);
	return sol;
}

int main()
{
	ios::sync_with_stdio(false);	
	cin.tie(0);
	
	cin>>n>>m;
	int a,b;
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		uviru[b]++;
		graf[a].push_back(b);
		grafNaopako[b].push_back(a);
	}
	int c;
	for(int i=1;i<=n;i++)
		if(uviru[i]==0)
		{	
			red.push(i);
		}
		
	while(!red.empty())
	{
		c=red.front();
		if(uviru[c]==0 && !marked[c])
		{
			topoloski[duzt++]=c;
			marked[c]=true;
			for(int i=0;i<graf[c].size();i++)
				red.push(graf[c][i]), uviru[graf[c][i]]--;
		}
		red.pop();
	}
	
	/*for(int i=0;i<duzt;i++)
		cout<<topoloski[i]<<" ";
	*/
	int sol=0;
	for(int i=0;i<duzt;i++)
		vrednosti[topoloski[i]]=resi(topoloski[i]), sol=max(sol,vrednosti[topoloski[i]]);
	cout<<sol;
	
	
	return 0;
}


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

int main(){
	string s,t;
	int ct=0;
	cin>>s>>t;
	for(int i=0; i<3; i++) 
	if(s[i]==t[i]) ct+=1;
	cout<<ct;
    return 0;
}




Measured memory_bytes: 256
N = int(input())
P = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]

dp = [1 << 29] * 10001
dp[0] = 0

for i in range(4):
    for j in range(1, t[i]):
        if dp[j] > P[i]:
            dp[j] = P[i]
    for j in range(t[i], 10001):
        dp[j] = min(dp[j], dp[j - t[i]] + P[i])

print(min(dp[N:]))



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

int main() {
  int n, k, d = 1000000007;
  cin >> n >> k;

  vector<int> h(n);
  for (int i = 0; i < n; i++) cin >> h[i];
  sort(h.begin(), h.end());

  for (int i = 0; i < n - k + 1; i++) d = min(d, h[i + k - 1] - h[i]);

  cout << d << endl;
}

Measured memory_bytes: 768
S = input()
s_cnt =0
t_cnt =0

for s in S:
    if s == 'S':
        s_cnt += 1
    if s == 'T':
        t_cnt += 1
        if s_cnt >0:
            t_cnt -= 1
            s_cnt -= 1
print(t_cnt + s_cnt)


Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5+5;
int A[MAXN];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&A[i]),A[i]-=i;
    sort(A+1,A+n+1);
    int x=(n+1)/2;
    long long Ans=0;
    for(int i=1;i<=n;i++)Ans+=abs(A[i]-A[x]);
    cout<<Ans<<'\n';
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	string s;
	cin >> s;
	vector<string> ss = {"dream", "dreamer", "erase", "eraser"};
	bool ans = true;
	while(ans){
		if(s.size() < 3){
			cout << "NO" << endl;
			return 0;
		}
		string id = s.substr(s.size()-3);
		ans = false;
		rep(i, 4){
			string ch = ss.at(i).substr(ss.at(i).size()-3);
			if(ch == id){
				if(s.size() < ss.at(i).size()) break;
				if(s.substr(s.size()-ss.at(i).size()) == ss.at(i)){
					s.erase(s.size()-ss.at(i).size());
					ans = true;
				}
				break;
			}
		}
		if(s.size() == 0)break;
	}
	if(ans == true) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

int main(){
	long n,sn,k,N;

	sn = 0;

	cin >> n;
	N = n;

	for (int i = 0; i < 10; i++) {
		k = 1;
		for (int j = 0; j < 9 - i; j++) {
			k *= 10;
		}
		sn += n / k;
		n %= k;
	}
	
	if (N % sn == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
if n % 2 == 1:
    for i in range(1,m+1):
        print(i,n-i)
    exit()
ans = []
if n % 4 == 0:
    for i in range(1,n//4+1):
        ans.append((i,n//2-i+1))
    for i in range(m-len(ans)):
        ans.append((n//2+2+i,n-i))
else:
    for i in range(2,n//4+2):
        ans.append((i,n//2-i+2))
    for i in range(m-len(ans)):
        ans.append((n//2+i+1,n-i))
for i in range(m):
    print(ans[i][0],ans[i][1])

Measured memory_bytes: 73020
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int h,n,a;
    cin>>h>>n;
    for(int i=0; i<n; i++){
        cin>>a;
        h=h-a;
    }
    if(h<=0){
        cout<< "Yes" <<endl;
    }
    else{
        cout<< "No" <<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;

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

    vector<int> ans(n+1);

    
    for(int i=n; i>=1; i--){
        int sum = 0;
        for(int j=i; j<=n; j+=i){
            sum += ans[j];
        }
        if(sum % 2 != v[i]) ans[i]++;
    }

    
    int cnt = 0;
    for(int i=1; i<=n; i++) cnt += ans[i];

    cout << cnt << endl;
    for(int i=1; i<=n; i++){
        if(ans[i] == 1) cout << i << " ";
    }
    cout << endl;
    
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

using namespace std;
using ll = long long;

int main() {
	ll n, k;
	cin >> n >> k;
	ll a = n / k;
	ll ans;
	ans = n - a * k;
	ans = min(ans, k - ans);
	cout << ans << endl;
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    ll a[n + 1], max[n + 1], min[n + 1];
    rep(i, n + 1) cin >> a[i];
    max[n] = min[n] = a[n];

    for (int i = n - 1; i >= 0; i--) {
        max[i] = max[i + 1] + a[i];
        min[i] = (min[i + 1] + 1) / 2 + a[i];
    }

    if (min[0] > 1) {
        cout << -1 << endl;
        return 0;
    }

    ll ans = 0, p = 1;
    rep(i, n + 1) {
        ans += p;
        p = (p - a[i]) * 2;
        if (p > max[i + 1]) p = max[i + 1];
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5924
n, m, k = map(int, input().split())
mod = 998244353

N = n + 5
bikkuri = [0 for i in range(N)]
bikkuri[0] = 1
gyaku = [0 for i in range(N)]
gyaku[0] = 1
for i in range(1, N):
    bikkuri[i] = (i * bikkuri[i - 1]) % mod
    gyaku[i] = pow(bikkuri[i], mod - 2, mod)


def comb(n, r):
    if r < 0 or n - r < 0:
        return 0
    if r == 0 or n - r == 0:
        return 1
    return (bikkuri[n] * gyaku[r] * gyaku[n - r]) % mod


ans = 0

for i in range(k + 1):
    ans += m * (pow(m - 1, n - i - 1, mod)) * comb(n - 1, i)
    ans %= mod
print(ans)


Measured memory_bytes: 94436
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

primeFactorization :: Int -> [(Int, Int)]
primeFactorization x = pfact x 2 0 []
  where
    sr = floor $ sqrt $ fromIntegral x
    pfact n i r fs | i > sr    = if n > sr then (n,1):fs else fs
                   | otherwise =
                     if n `mod` i == 0
                     then pfact (n `div` i) i (r+1) fs
                     else pfact n (i+1) 0 (if r > 0 then (i,r):fs else fs)
main = do
  n <- getInt
  let pfs = primeFactorization n

      divE e i s | i + s > e = i - 1
                 | otherwise = divE e (i+1) (s+i)

      solve [] res = res
      solve ((p,e):xs) res = let c = divE e 1 0
                             in solve xs (res+c)

  print $ solve pfs 0


Measured memory_bytes: 60488