akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func divFloor(a, b int) int {
	return (a + (b - 1)) / b
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, a, b := nextInt(), nextInt(), nextInt()
	h := nextInts(n)

	// x回の攻撃で倒せるか
	canKillAll := func(x int) bool {
		acnt := 0
		for i := 0; i < n; i++ {
			acnt += divFloor(max(0, h[i]-b*x), a-b)
		}
		return acnt <= x
	}

	low, high := 0, 1000000001
	for low < high {
		mid := (low + high) / 2
		if canKillAll(mid) {
			high = mid
		} else {
			low = mid + 1
		}
	}

	puts(low)
}


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

using namespace std;

class UnionFind {
public:
    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 size(int x) { return -data[root(x)]; }

private:
    std::vector<int> data;
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
};


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

    int n, m;

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

    UnionFind uf(n);
    for (int i = 0, x, y; i < m; ++i) {
        cin >> x >> y;
        uf.UnionSet(x - 1, y - 1);
    }

    int cnt = 0;
    for (int i = 0; i < n; ++i)
        if (uf.FindSet(i, p[i])) ++cnt;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 1024
import math
K = int(input())
p = int(K*(K+1)/2)
for a in range(K):
    for b in range(a+1, K):
        g = math.gcd(a+1, b+1)
        p += 6*g
        for c in range(b+1, K):
                p += 6*math.gcd(g, c+1)
print(p)


Measured memory_bytes: 9184
ans = input()
q = int(input())
r = 0
p = ""
for i in range(q):
    d = input().split()
    if len(d)==1:
        r += 1
    else:
        f = int(d[1])
        c = d[2]
        if (f+r)%2 == 1:
            p += c
        else:
            ans += c
ans = p[::-1] + ans
if r%2:
    ans = ans[::-1]
print(ans)

Measured memory_bytes: 4192
#include<stdio.h>
int main()
{
  int a,b,c,d,e,k;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
  scanf("%d",&e);
  scanf("%d",&k);
  if(e-a>k)
  {
    printf(":(\n");
  }
  else
  {
    printf("Yay!\n");
  }
  return 0;
}
  

Measured memory_bytes: 128
#include<iostream>
using namespace std;
#define ll long long
const int maxn = 55;
ll x[maxn], y[maxn], a[maxn], b[maxn];
int n, m;
int main(){
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
		cin >> x[i] >> y[i];
	for (int j = 0; j < m; ++j)
		cin >> a[j] >> b[j];

	for (int i = 0; i < n; ++i){
		int ans = 0;	ll minn = 1e9 + 7;
		for (int j = 0; j < m; ++j)
		{
			ll sum = abs(x[i] - a[j]) + abs(y[i] - b[j]);
		//	cout << "sum=" << sum << "--"<<minn<<endl;
			if (sum < minn){ minn = sum;  ans = j + 1; }
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    int n;cin>>n;
    int N=n/2;
    map<int,int> mp1,mp2;
    for(int i=0;i<N;i++){
        int a,b;cin>>a>>b;
        mp1[a]++;
        mp2[b]++;
    }

    priority_queue<int> pque1,pque2;
    pque1.push(0),pque2.push(0);
    for(int i=1;i<=100000;i++){
        pque1.push(mp1[i]);
        pque2.push(mp2[i]);
    }
    int m1=pque1.top();
    int m2=pque2.top();
    pque1.pop(),pque2.pop();
    if(m1==pque1.top()||m2==pque2.top())
        cout<<n-m1-m2<<endl;
    else {
        int t1,t2;
        for(auto itr1=mp1.begin();itr1!=mp1.end();itr1++)
            if(itr1->second==m1)t1=itr1->first;
        for(auto itr2=mp2.begin();itr2!=mp2.end();itr2++)
            if(itr2->second==m2)t2=itr2->first;  
        if(t1!=t2)cout<<n-m1-m2<<endl;
        else cout<<min(n-m1-pque2.top(),n-m2-pque1.top())<<endl;     
    }
    return 0;
}

Measured memory_bytes: 10352
//Vacation

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;cin>>n;
    vector<vector<int>>dp(n+1,vector<int>(3,0));
    //何日目、最後の行動
    rep(i,1,n+1){
        int a,b,c;cin>>a>>b>>c;
        dp[i][0]=max(dp[i-1][1]+a,dp[i-1][2]+a);
        dp[i][1]=max(dp[i-1][0]+b,dp[i-1][2]+b);
        dp[i][2]=max(dp[i-1][0]+c,dp[i-1][1]+c);
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<nnn;
    return 0;
}

Measured memory_bytes: 8804
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int len = s.size();
  string answer = "";
  int counter = 0;
  for(int i = 0 ; i < len; ++i){
    if(s[i] == 'B'){
     if(counter > 0) --counter;
    } 
    else {
      ++counter;
      answer[counter-1] = s[i];
    }
  }
  for(int i = 0 ; i < counter; ++i)
    cout << answer[i];
  cout << endl;
}

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

const int INF = 1e9;
using ll = long long;

int n,m;

vector<pair<ll,ll>> es;

map<ll,ll> s;
int k = 0;
ll id(int v, int c){
    ll x = (ll)v<<32|c;
    if(s.count(x)) return s[x];
    s[x] = k++;
    return s[x];
}

unordered_set<int> cs[100010];

struct edge { int dst, wgt; };

vector<edge> g[500010];

void ae(int a, int b, int w){
    g[a].push_back({b,w});
    g[b].push_back({a,w});
}

deque<int> q;
int dist[500010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> n >> m;
    rep(i,n) cs[i].insert(id(i,0));
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        --a; --b;
        ll x = id(a,c);
        ll y = id(b,c);
        es.emplace_back(x,y);
        cs[a].emplace(x);
        cs[b].emplace(y);
    }
    int k = 0;
    unordered_map<ll,int> idid;
    for(auto &p : s){
        idid[p.second] = k++;
    }
    for(auto &e : es){
        ll a,b;
        tie(a,b) = e;
        int x = idid[a];
        int y = idid[b];
        ae(x,y,0);
    }

    rep(i,n){
        int h = idid[id(i,0)];
        for(auto &c : cs[i]) if(c != h) ae(h,idid[c],1);
    }

    int ans = -1;

    int src = idid[id(0,0)];
    int dst = idid[id(n-1,0)];
    fill(dist, dist+k, INF);
    dist[src] = 0;
    q.push_back(src);
    while(q.size()){
        int v = q.front();
        q.pop_front();

        if(v == dst){
            ans = dist[v]/2;
            break;
        }

        for(auto &e : g[v]){
            if(dist[e.dst] != INF) continue;
            dist[e.dst] = dist[v] + e.wgt;
            if(e.wgt == 0) q.push_front(e.dst);
            else q.push_back(e.dst);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 117868
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

void precalc() {
}

const int maxn = (int) 2e5 + 10;
int n;

int a[maxn], b[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", b + i);
  }
  return 1;
}

const int mod = (int) 1e9 + 7;

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int xs[maxn];

struct ftree {
  int n;
  int a[maxn];

  void build(int _n) {
    n = _n;
    for (int i = 0; i < n; ++i) {
      a[i] = 0;
    }
  }

  void add(int x, int toadd) {
    for (; x < n; x |= (x + 1)) {
      a[x] += toadd;
    }
  }

  int get(int x) {
    int res = 0;
    for (; x >= 0; x = (x & (x + 1)) - 1) {
      res += a[x];
    }
    return res;
  }
} tree;

void solve() {
  sort(a, a + n);
  sort(b, b + n);

  merge(a, a + n, b, b + n, xs);
  tree.build(2 * n);

  int res = 1;
  for (int i = 0; i < n; ++i) {
    int pos1 = lower_bound(xs, xs + 2 * n, a[i]) - xs;
    int pos2 = lower_bound(xs, xs + 2 * n, b[i]) - xs;
    if (pos1 > pos2) {
      swap(pos1, pos2);
    }
    res = mult(res, tree.get(pos2) - tree.get(pos1) + 1);
    tree.add(pos1, 1);
    tree.add(pos2, 1);
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll a,b;
int32_t main(){
CODE_START;
cin>>a>>b;
if(b>=a){
    cout<<"Yes"<<endl;
}else cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <cmath>
#include <algorithm>
#include <vector>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main(){
  string s;
  cin>>s;
  int N=s.size();
  bool ok=true;
  for(int i=0;i<N;i++){
    if(s[i]!=s[N-1-i]){ok=false;}
  }
  for(int i=0;i<(N-1)/2;i++){
    if(s[i]!=s[(N-1)/2-1-i]){ok=false;}
  }
  for(int i=(N+3)/2-1;i<N;i++){
    if(s[i]!=s[N-1-i]){ok=false;}
  }
  if(ok){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  return 0;
}

Measured memory_bytes: 3620
# -*- coding: utf-8 -*-
"""
D - Knapsack 1
https://atcoder.jp/contests/dp/tasks/dp_d

"""
import sys


def solve(N, W, items):
    dp = [0-1] * (W+1)
    dp[0] = 0
    for w, v in items:
        for i in range(W, w-1, -1):
            if dp[i-w] != -1:
                dp[i] = max(dp[i], dp[i-w]+v)
    return max(dp)



def main(args):
    N, W = map(int, input().split())
    items = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, W, items)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 40048
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
ll a[1010],b[1010],c[1010];
vector<ll> v,v1;
int main()
{
	int i,j,k,n,m,x,y,z,w;
	scanf("%d%d%d%d",&x,&y,&z,&w);
	for(i=0;i<x;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(i=0;i<y;i++)
	{
		scanf("%lld",&b[i]);
	}
	for(i=0;i<z;i++)
	{
		scanf("%lld",&c[i]);
	}
	for(i=0;i<x;i++)
	{
		for(j=0;j<y;j++)
		{
			v.push_back(a[i]+b[j]);
		}
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	v.resize(w);
	for(i=0;i<v.size();i++)
	{
		for(j=0;j<z;j++)
		{
			v1.push_back(v[i]+c[j]);
		}
	}
	sort(v1.begin(),v1.end());
	reverse(v1.begin(),v1.end());
	for(i=0;i<w;i++)
	{
		printf("%lld\n",v1[i]);
	//	cout<<v[i]<<endl;
	}
	return 0;
}



Measured memory_bytes: 43364
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn gcd(a: u64, b: u64) -> u64{
    if b == 0{
        return a;
    }else{
        return gcd(b, a%b);
    }
}

fn calc_prime_divisors(mut x: u64) -> Vec<u64>{
    let mut res = vec![1];

    for div in 2..(x as f64).sqrt().ceil() as u64+1{
        if x%div == 0{
            res.push(div);
        }

        while x%div == 0{
            x /= div;
        }
    }

    if x > 1{
        res.push(x);
    }
    return res;
}

fn main(){
    let line = read_as_vec::<u64>();

    let (a, b) = (line[0], line[1]);

    let gcd = gcd(a, b);
    let prime_divisors = calc_prime_divisors(gcd);
    println!("{}", prime_divisors.len());

}


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

#define int unsigned long long
#define counter(m)     for(int i=0;i<m;i++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            (long long)1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int32_t main() {
    nitin;
    int n;
    cin>>n;
    cout<<(power(10,n,mod)-power(9,n,mod)-power(9,n,mod)+power(8,n,mod)+((long long)10)*mod)%mod<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
string a;
int main()
{
cin>>a;
for(int i=1;i<a.size();i++)
if(a[i]==a[i-1])
{
cout<<i<<" "<<i+1<<endl;
return 0;
}
for(int i=2;i<a.size();i++)
if(a[i]==a[i-2])
{
cout<<i-1<<" "<<i+1<<endl;
return 0;
}
cout<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 512
use std::io::*;

fn main() {
    let stdin = stdin();
    let mut handle = stdin.lock();
    let k = read(&mut handle);
    let n = read(&mut handle);
    let mut a_vec = Vec::new();
    for _ in 0..n as usize {
        a_vec.push(read(&mut handle));
    }

    let mut res: u64 = 0;
    for i in 0..n as usize {
        if i < n as usize - 1 {
            let temp: u64 = (*a_vec.get(((i + 1) as u64 % n) as usize).unwrap() as i64
                - *a_vec.get(i).unwrap() as i64)
                .abs() as u64;
            if temp > res {
                res = temp;
            }
        } else {
            let temp: u64 = (*a_vec.get(((i + 1) as u64 % n) as usize).unwrap() as i64 + k as i64
                - *a_vec.get(i).unwrap() as i64)
                .abs() as u64;
            if temp > res {
                res = temp;
            }
        }
    }
    println!("{}", k - res);
}

fn read(handle: &mut StdinLock) -> u64 {
    handle
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .fold(0, |acc, x| (x as u8 - b'0') as u64 + acc * 10)
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define ll long long
#define re register
#define ull unsigned ll
using namespace std;
#define int ll
inline int read(){
	int s=0,t=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*t;
}
int Lowbit(int x){int t=-1;while(x)x>>=1,t++;return t;}
int Calc(int a,int b,int c,int d){
	if(b<c)return b-a+1+d-c+1;
	return d-a+1;
}
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int L=read(),R=read(),d=0;
	if(L==R)return printf("1"),0;
	for(d=62;d>=0;d--)if((L>>d&1)^(R>>d&1))break;
	L&=(1ll<<d+1)-1,R&=(1ll<<d+1)-1;
	int T=1ll<<d,D=Lowbit(R&(T-1));
	int Ans=T-L+Calc(T,T+(1ll<<D+1)-1,T+L,2*T-1);
	printf("%lld",Ans);
	return 0;
}


Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
int n;
int a[200100],b[200100];
int l[200100],r[200100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<=n;i++){
		if(a[i]>b[i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	for(int i=2;i<=n;i++)
		l[i]=i-1;
	l[1]=n;
	for(int j=1;j<n;j++)
		r[j]=j+1;
	r[n]=1;
	long long res=0LL;
	int cnt=0;
	while(1){
		bool ok=true,chg=false;
		for(int i=1;i<=n;i++){
			if(b[i]==a[i])
				continue;
			if(b[i]<a[i]){
				cout<<-1<<endl;
				return 0;
			}
			ok=false;
			long long he=(long long)(b[l[i]]+b[r[i]]);
			if(b[i]-he<a[i])
				continue; 
			res+=(long long)((b[i]-a[i])/he);
			b[i]-=((b[i]-a[i])/he)*he;
			chg=true;
		}
		if(ok)
			break;
		if(!chg){
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 3328
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

vector<int> parent;
vector<int> nodes;

int getParent(int x) {
  int y = x;
  while (y != parent[y]) y = parent[y];
  parent[x] = y;
  return y;
}

void unite(int x, int y) {
  x = getParent(x);
  y = getParent(y);
  if (x == y) return;

  if (nodes[x] < nodes[y]) swap(x, y);
  parent[y] = x;
  nodes[x] += nodes[y];
}

int main(void) {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;

  parent.resize(N);
  nodes.resize(N);
  rep(i, N) {
    parent[i] = i;
    nodes[i] = 1;
  }

  rep(i, M) {
    int A, B;
    cin >> A >> B;
    A--, B--;
    unite(A, B);
  }

  int answer = 0;
  rep(i, N) {
    if (i == getParent(i)) {
      answer = max(answer, nodes[i]);
    }
  }
  cout << answer << endl;
  return 0;
}


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

int main() {
  ll n;
  cin >> n;
  map<int,int> a;
  for(ll i=2;i<=pow(n,0.5);i++){
    if(n%i!=0)
      continue;
    while(n%i==0){
        a[i]++;
        n=n/i;
    }
  }
  if(n!=1)
    a[n]++;
  int count=0;
  for (auto p : a) {
    auto k = p.first;
    auto v = p.second;
    int z=v;
    int i=1;
    while(z-i>=0){
      z=z-i;
      i++;
      count++;
    }
  }
  cout << count << endl;
}



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

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const int MAX_N = 100;

struct matrix {
    int r;
    int c;
};

ll dp[MAX_N + 1][MAX_N + 1];

ll solve(const int i, const int j, const vector<struct matrix> &matrices) {
    if (j <= i) return 0;
    if (j - i == 1) return matrices[i].r * matrices[i].c * matrices[j].c;
    if (dp[i][j] != LONG_LONG_MAX / 2) return dp[i][j];

    ll answer = LONG_LONG_MAX / 2;
    for (int k = i; k < j; k++) {
        chmin(answer, solve(i, k, matrices) + solve(k + 1, j, matrices) + matrices[i].r * matrices[k].c * matrices[j].c);
    }

    dp[i][j] = answer;
    return answer;

    // for (int i = 1; i <= N; i++) {
    //     int j = i + 1;
    //     dp[i][j] = matrices[i].r * matrices[i].c * matrices[j].c;
    //     j++;
    //     for (; j <= N; j++) {
    //         for (int k = i + 1; k < j; k++) {
    //             chmin(dp[i][j], dp[i][k] + dp[k + 1][j] +
    //                     matrices[i].r * matrices[k].c * matrices[j].c);
    //         }
    //     }
    // }
    // 
    // return dp[1][N];
}

int main(void) {
    int N;
    cin >> N;
    vector<struct matrix> matrices(N + 1);

    for (int i = 1; i <= N; i++) {
        cin >> matrices[i].r >> matrices[i].c;
    }

    for (int i = 1; i <= MAX_N; i++) {
        for (int j = i + 1; j <= MAX_N; j++) {
            dp[i][j] = LONG_LONG_MAX / 2;
        }
    }

    cout << solve(1, N, matrices) << endl;

    // for (int i = 0; i <= N; i++) {
    //     for (int j = 0; j <= N; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    
    return 0;
}



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

using namespace std;

int main() {
    long long n;
    cin>>n;
    string str;
    while(n)
    {
        str +=(--n%26 + 'a');
        n = n/26;
    }
    for(int i=0;i<str.length();i++)
    {
        cout<<str[str.length()-i-1];
    }
}


Measured memory_bytes: 3624
/*
 * atcoder/abc132_3rd/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
/* Mod */
#define MOD 1000000007
template <class T> void madd(T &a, T b){ if((a+=b)>=MOD) a-=MOD; }
template <class T> void msub(T &a, T b){ if((a+=MOD-b)>=MOD) a-=MOD; }


struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%MOD+MOD)%MOD; return *this;}
  mint operator-() const { return mint(0) - *this;}
  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;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
ostream & operator << (ostream & out, mint const & v) {
  out << v.x;
  return out;
}

/* nCk */
template<class T> struct BiCoef {
    vector<T> fact_, inv_, finv_;
    constexpr BiCoef() {}
    constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
        init(n);
    }
    constexpr void init(int n) noexcept {
        fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
        for(int i = 2; i < n; i++){
            fact_[i] = fact_[i-1] * i;
            inv_[i] = -inv_[MOD%i] * (MOD/i);
            finv_[i] = finv_[i-1] * inv_[i];
        }
    }
    constexpr T com(int n, int k) const noexcept {
        if (n < k || n < 0 || k < 0) return 0;
        return fact_[n] * finv_[k] * finv_[n-k];
    }
    constexpr T fact(int n) const noexcept {
        if (n < 0) return 0;
        return fact_[n];
    }
    constexpr T inv(int n) const noexcept {
        if (n < 0) return 0;
        return inv_[n];
    }
    constexpr T finv(int n) const noexcept {
        if (n < 0) return 0;
        return finv_[n];
    }
};

int N, K;
BiCoef<mint> bc;
void solve() {
  cin >> N >> K;
  bc.init(2001);
  loop(k,1,K+1) {
    cout << bc.com(K-1, K-k) * bc.com(N-K+1, k) << endl;
  }
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>

int main() {
    using namespace std;


    long long N,A,B;
    cin >> N >> A >> B;
    long long X[N];
    long long dist[N];

    for (int i=0;i < N;++i)
        cin >> X[i];

    long long curSum = 0;
    for (int K=0;K<N-1;++K)
    {
        dist[K] = X[K+1] - X[K];
        long long walk = dist[K]*A;
        curSum += min(walk,B);
    }

    cout << curSum << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	if (n == 3) {
		cout << 2 << endl;
		cout << "1 3\n2 3\n";
	}
	else if (n == 4) {
		cout << 4 << endl;
		cout << "1 2" << endl;
		cout << "1 3" << endl;
		cout << "2 4" << endl;
		cout << "3 4" << endl;
	}
	else if (n % 2 == 0) {
		cout << 2 * n << endl;
		for (int i = 1;i <= n / 2;i++) {
			if (i == n / 2) {
				cout << i << " " << 1 << endl;
				cout << i << " " << n << endl;
				cout << i + 1 << " " << 1 << endl;
				cout << i + 1 << " " << n << endl;
			}
			else {
				cout << i << " " << i + 1 << endl;
				cout << i << " " << n - i << endl;
				cout << (n + 1) - i << " " << i + 1 << endl;
				cout << (n + 1) - i << " " << n - i << endl;
			}
		}
	}
	else {
		cout << 2 * n - 2 << endl;
		cout << 1 << " " << n << endl;
		cout << n - 1 << " " << n << endl;
		for (int i = 1;i <= n / 2;i++) {
			if (i == n / 2) {
				cout << i << " " << n << endl;
				cout << i + 1 << " " << n << endl;
			}
			else {
				cout << i << " " << i + 1 << endl;
				cout << i << " " << n - 1 - i << endl;
				cout << n - i << " " << i + 1 << endl;
				cout << n - i << " " << n - 1 - i << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,m;
int main() {
	cin>>n>>m;
	for(int i=n;i<=m;i++){
		if(m%i==0){
			cout<<m/i<<endl;
			return 0;
		}else if(i>m/2){
			cout<<1<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
function Main(input){
  input = input.split("\n");
  let s = input[0];
  let t = input[1];
  let count = 0;
  for(var i=0;i<s.length;i++){
    if(s[i] !== t[i]) count++;
  }
  console.log(count);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 34440
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef pair<ll,ll> p;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
ll ncr(ll n,ll r, vector<ll>&fact)
{
    if(n<r)
    {
        return 0ll;
    }
    if(n==r)
    {
        return 1ll;
    }
    if(r==1)
    {
        return n;
    }
    if(r==0)
    {
        return 1ll;
    }
    ll num=fact[n];
    ll den=(fact[r]*fact[n-r])%mod;
    den=power(den,mod-2);
    return (num*den)%mod;

}
int main()
{
fast;
ll h;
cin>>h;
string s;
cin>>s;
ll k=s.size();
ll n=k+h;
ll ans=0;
vector<ll>fact(n+1,1);
for(ll i=1;i<=n;i++)
{
    fact[i]=(i*fact[i-1])%mod;
}
for(ll x=0;x<=n-k;x++)
{
    ll a=power(26ll,x);
    ll b=power(25ll,n-x-k);
    ll c=ncr(n-x-1,k-1,fact);
    ll val=(a*b)%mod;
    val=(val*c)%mod;
    ans=(ans+val)%mod;

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


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define N_ALPHABET 26
i64 N;
string A;

char shift(char c) {
    i64 offset = c - 'A';
    return 'A' + (offset + N) % N_ALPHABET;
}

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

    REP(i, A.length()) {
        cout << shift(A[i]);
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
int main(void){
 
    int i,j,h,w;
 
    while(1){
 
        scanf("%d %d",&h,&w);
        if(h==0&&w==0)break;
 
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                if(i==0||i==h-1)printf("#");
                else if(j==0||j==w-1)printf("#");
                else printf(".");
            }
            printf("\n");
        }
 
        printf("\n");
 
    }
 
    return 0;
 
}
        

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int count =0;
  for (int i=0; i <= a; i++){
    for (int j=0; j <= b; j++){
      for (int k=0; k <= c; k++){
        if(500*i + 100*j + 50*k == x){
          count++;
        }
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;
 class Main  {
     public static void main(String[]args){
         Scanner scan = new Scanner(System.in);
         int n = scan.nextInt();
         int m = scan.nextInt();
         int x = scan.nextInt();
         ArrayList<Integer> a = new ArrayList<>();
         for(int i = 0 ; i<m;i++){
             a.add(scan.nextInt());
         }
         int max ;
  
         int cost = 0 ;
         for(int i = 1 ; i< x ; i++){
             if(a.contains(i)){
                 cost++;
             }
         }
         
         int cost2 = 0 ;
         for(int i = x+1 ; i< n+1 ; i++){
             if(a.contains(i)){
                 cost2++;
             }
         }
         System.out.println(Math.min(cost,cost2));
     }
}


Measured memory_bytes: 22484
import math
n = int(input())
heap = [None] + list(map(int, input().split()))
for i, x in enumerate(heap):
    if i == 0:
        continue
    p = math.floor(i / 2)
    parent = ''
    if 1 <= p:
        parent = "parent key = {}, ".format(heap[p])
    left = i * 2
    l = ''
    if left <= n:
        l = 'left key = {}, '.format(heap[left])
    right = i * 2 + 1
    r = ''
    if right <= n:
        r = 'right key = {}, '.format(heap[right])

    ans = "node {i}: key = {key}, {parent}{l}{r}".format(i=i, key=x, parent=parent, l=l, r=r)
    print(ans)

Measured memory_bytes: 7704
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
using namespace std;

#define ll long long

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}

int main() {

	ll N;
	cin >> N;

	for (ll i = 1; i <= 3500; i++) {
		for (ll j = i; j <= 3500; j++) {

			if (4 * i*j - N*i - N*j > 0) {
				if ((N*i*j) % (4 * i*j - N*i - N*j) == 0) {
					
					cout << (N*i*j) / (4 * i*j - N*i - N*j) << " " << i << " " << j << endl;
					return 0;

				}
			}

		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]){
    int a[101],i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=n-1;i>=1;i--){
        printf("%d ",a[i]);
    }
    printf("%d\n",a[0]);
    return 0;
}


Measured memory_bytes: 2068
#include<stdio.h>
int main(void){
    int ans,i,min,a;
    for(i = 0,ans = 0,min = 100;i < 4;i++){
        scanf("%d",&a);
        if(min >= a) min = a;
        ans += a;
    }
    ans -= min;
    scanf("%d %d",&a,&min);
    if(min >= a)    ans += min;
    else            ans += a;
    printf("%d\n",ans);
}


Measured memory_bytes: 2132
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, kk;
	cin >> nn >> kk;
	vector<int64> pp(nn + 1, 0);
	long double ans = 0, tmp;
	for(int64 ii = 1;ii <= nn;ii++)
	{
		cin >> pp[ii];
		pp[ii] += 1;
		pp[ii] += pp[ii - 1];
	}
	for(int64 ii = 0;ii <= (nn - kk);ii++)
	{
		tmp = pp[ii + kk] - pp[ii];
		tmp /= 2.0;
		ans = ans < tmp ? tmp : ans;
	}
	cout << fixed << setprecision(15) << ans << endl;;
	return 0;
}


Measured memory_bytes: 4844
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <functional>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;




int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    if(n == 1 && m == 1) {
        ans = 1;
    }
    else if(n == 1) {
        ans = m - 2;
    }
    else if(m == 1) {
        ans = n - 2;
    }
    else {
        ans = (n - 2) * (m - 2);
    }
    cout << ans;


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define stdi(in) freopen(in, "r", stdin)
#define stdo(out) freopen(out, "w", stdout)
#define stdio(in, out) stdi(in); stdo(out)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define MAX 100007
#define MOD 1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define ordered_set tree<int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

ll arr[102],n,k;
//ll dp[102][MAX];
ll presum[102][MAX];

int main(){
    /*#ifndef ONLINE_JUDGE
        stdio("in", "out");
    #endif*/
    fast;
    cin>>n>>k;

    for(int i=1;i<=n;i++){
    	cin>>arr[i];
    }

    if(k==0){
    	cout<<1<<'\n';
    	return 0;
    }

    /*for(int i=0;i<=n;i++){
    	dp[i][0] = 1;
    }*/

    ll ans = 0;
    for(int i=1;i<=k;i++){
    	ans = 0;
    	if(arr[1]>=i){
	    	ans = 1;
	    }
    	presum[1][i] = presum[1][i-1]+ans;
    }

    for(int i=2;i<=n;i++){
    	for(int j=1;j<=k;j++){
    		ans = presum[i-1][j]-presum[i-1][max(j-arr[i]-1, 0LL)];
    		if(arr[i]>=j) ans++;
    		if(ans<0) ans+=MOD;
    		presum[i][j] = (presum[i][j-1]+ans)%MOD;
    	}
    }

    cout<<ans<<'\n';


    return 0;   
}

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

int main() {
  int N; cin >> N;
  set<string> U;
  for(int i = 0; i < N; ++i) {
    string id; cin >> id;
    U.insert(id);
  }
  int M; cin >> M;
  for(bool door = 0; M--; ) {
    string id; cin >> id;
    if(U.count(id)) {
      if(door) cout << "Closed by " << id << endl;
      else cout << "Opened by " << id << endl;
      door ^= 1;
    } else {
      cout << "Unknown " << id << endl;
    }
  }
  return 0;
}

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

int main()
{
    int N, check=0;
    char s[100];

    cin >> N;
    for (int i=0; i<N; i++){
        cin >> s[i];
        if (s[i] == 'Y')   check=1;
    }
    if (check==1)   cout << "Four" << endl;
    else cout << "Three" << endl;

    return 0;
}


Measured memory_bytes: 256
#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 all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){return (int)s.size();}
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int h,w; cin >> h >> w;
    vc<string> a(h);
    rep(i,h){
        cin >> a[i];
    }
    rep(i,h){
        cout << a[i] << endl << a[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
int x[100],c=0;
using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
        scanf("%d",&x[i]);
    for(int i=0; i<n-1; i++)
    {
        int minn=i;
        for(int j=i+1; j<n; j++)
        {
            if(x[j]<x[minn])
            {
                minn=j;
            }
        }
        if(minn!=i)
        {
            swap(x[i],x[minn]);
            c++;
        }
    }
    for(int k = 0; k < n; k++)
    {
        if(k != n-1)
        {
            printf("%d ",x[k]);
        }
        else
        {
            printf("%d\n",x[k]);
        }
    }
    cout<<c<<endl;
    return 0;
}




Measured memory_bytes: 3280
MOD = 1000000007

pattern = [0] * 10
pattern[0] = 1
pattern[1] = 1
for i in range(2, 8 + 1):
    pattern[i] = pattern[i-1] + pattern[i-2]


def single_down(idx_from, idx_to, W):
    if idx_from == idx_to:
        return pattern[idx_from - 1] * pattern[W - idx_from]
    else:
        left = min(idx_from, idx_to) - 1
        right = W - max(idx_from, idx_to)
        return pattern[left] * pattern[right]


def main():
    H, W, K = map(int, input().split())

    ptn = [[0] * W]
    ptn[0][0] = 1
    for h in range(1, H + 1):
        ptn.append([])
        ptn[h] = [0] * W
        for w in range(0, W):
            ptn[h][w] = ptn[h-1][w] * single_down(w+1, w+1, W) % MOD
            if w > 0:
                ptn[h][w] += ptn[h-1][w-1] * single_down(w, w+1, W) % MOD
            if w < W-1:
                ptn[h][w] += ptn[h-1][w+1] * single_down(w+2, w+1, W) % MOD
            ptn[h][w] %= MOD

    print(ptn[H][K-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 38768
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n+1) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n+1);
	vector<vector<int> > cnt(n+1,vector<int>(70));
	reps(i,n){
		cin >> a[i];
		int tmp = a[i];
		for(int j = 0;j < 62;++j){
			cnt[i][j] = cnt[i-1][j] + (tmp % 2 == 1);
			cnt[i][j];
			tmp >>= 1;
		}
	}
	/*
	reps(i,n){
		rep(j,65){
			cout << (j == 0 ? "" : " ") << cnt[i][j];
		}
		cout << '\n';
	}
	*/
	int sum = 0;
	for(int i = 1;i < n;++i){
		rep(j,61){
			int tmp = cnt[n][j] - cnt[i][j];
			if(a[i] & (1ll << j)){
				(sum += ((n-i) - tmp) * ((1ll << j) % mod)) %= mod;
			}
			else{
				(sum += tmp * ((1ll << j) % mod)) %= mod;
			}
		}
	}
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 178432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
struct Edge {ll s,t,d;};
typedef vector<vector<Edge>> Graph;

int main(){
  int N; cin>>N;
  int cnt=0;
  REP(i,N) {
    int x; cin>>x;
    if(x%2) cnt++;
  }

  if(cnt%2) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
int N, n100, n10, n1;
scanf("%d", &N);

n100 = N / 100;
n10 = (N - n100 * 100) / 10;
n1 = N % 10;

if(n1==7 || n10==7 || n100==7){
printf("Yes");
}else{
printf("No");
}
}

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

int main() {
  int N;
  cin>>N;
  vector<int> card(N);
  
  for(int i=0;i<N;i++){
   cin>>card.at(i);  //配列にカードの数字を入れていく
  } 
  sort(card.begin(),card.end()); //カードを小さい順に
  reverse(card.begin(),card.end()); //カードを大きい順にする
 
   //AliceとBobの合計点を求める
  
  int suma=0;
  int sumb=0;
  for(int i=0;i<N;i+=2){
      suma+=card.at(i);
  }
  for(int i=1;i<N;i+=2){
      sumb+=card.at(i);
  }
  
  cout<<suma-sumb<<endl;
}
  

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

using namespace std;

int S[100010];

int main(int argc, char *argv[])
{
  int N, ans = 0, minv = 2000000, maxv = -1;
  cin >> N;
  map<int, int> m;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
    m[S[i]]++;
  }
  sort(S, S + N);

  if (N < 3) {
    if (abs(S[0]-S[1]) <= 1) {
      ans = 2;
    } else {
      ans = 1;
    }
  } else {
    for (int i = 0; i < N-2; i++) {
      ans = max(ans, m[i] + m[i + 1] + m[i + 2]);
    }
  }

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


Measured memory_bytes: 5376
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <deque> 

using namespace std;


//跟插入的方式相反，倒过来做 
int n;
int b[110];
int ans[110];	//结果是倒过来输出的 

int main()
{
	scanf("%d", &n);
	for (int i = 1 ; i <= n ; i++)
		scanf("%d", &(b[i]));
		
	int szB = n;
	for (int pAns = n ; pAns >= 1 ; pAns--) 
	{
		//每次找到最大的，符合b[i]=i的数据，然后删除之
		int curMaxP = -1;
		int p = 1;
		while (p <= szB)
		{
			if (b[p] == p)
			{
				curMaxP = p;//因为p一直在上升，所以不需要比大小 
			}
			p++;
		}
		
		//如果找不到，那就是失败的 
		if (curMaxP == -1)
		{
			printf("-1\n");
			return 0;
		}
		else
		{
			ans[pAns] = curMaxP;	//装载答案 
			
			//删掉一个节点 
			for (int i = curMaxP + 1 ; i <= szB ; i++)
				b[i - 1] = b[i];
			szB--;
		}
	}
	
	
	for (int i = 1 ; i <= n ; i++)	
		printf("%d\n", ans[i]);
	
	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[100001];
ll cnt[100001];

int main(void){
	scanf("%d",&n);
	ll sum=0;
	ll loopsum=0;
	for(int i=1;i<=n;i++){
		loopsum+=(ll)i;
	}
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		sum+=a[i];
	}
	if(sum%loopsum!=0){
		printf("NO\n");
		return 0;
	}
	ll loopnum=sum/loopsum;
	for(int i=0;i<n;i++){
		ll diff=a[(i+1)%n]-a[i];
		cnt[i]+=(loopnum-diff)/n;
	}
	ll cntsum=0;
	for(int i=0;i<n;i++){
		if(cnt[i]<0 || cnt[i]>loopnum){
			printf("NO\n");
			return 0;
		}
		cntsum+=cnt[i];
	}
	printf("%s\n",(cntsum==loopnum)?"YES":"NO");
	return 0;
}


Measured memory_bytes: 1792