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

public class Main {

    public static final int BIG_NUM = 2000000000;
    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        int array[] = new int[N];
        for(int i = 0; i < N; i++){
            array[i] = scanner.nextInt();
        }

        out_put(array);

        int base, loc;
        for(int i = 1; i < N; i++){
            base = array[i];
            loc = i - 1;
            while(loc >= 0 && array[loc] > base){
                array[loc+1] = array[loc];
                loc--;
            }
            array[loc+1] = base;

            out_put(array);
        }

    }

    private static void out_put(int array[]){
        int i;
        for(i=0; i<array.length-1; i++){
            System.out.print(array[i] + " ");
        }
        System.out.println(array[i]);

        }
}



Measured memory_bytes: 32136
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#define rep(i,n) for(int i=0;i<n;++i)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
int main() {
	int A, B, C, X, Y;	cin >> A >> B >> C >> X >> Y;
	int AB = 2 * C, price, ans = mod;
	rep(i, 100001) ans = min(ans, AB * i + A * max(0, X - i) + B * max(0, Y - i));
	cout << ans << endl;
	cin >> A;
}


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

public class Main {
    int n, m;
    int MOD = 1000000007;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        m = sc.nextInt();
        solve();
    }

    void solve() {
        if (n > m) {
            int temp = n;
            n = m;
            m = temp;
        }
        if (m - n > 1) {
            System.out.println(0);
            return;
        }
        long ans = 0;
        long[] facts = fillFactorial(m, MOD);
        if (n == m) {
            ans = 2 * facts[n] * facts[m] % MOD;
        } else {
            ans = facts[n] * facts[m] % MOD;
        }
        System.out.println(ans);
    }

    long[] fillFactorial(int max, int mod) {
        long[] facts = new long[max + 1];
        facts[0] = 1;
        for (int i = 1; i < facts.length; i++) {
            facts[i] = facts[i - 1] * i % mod;
        }
        return facts;
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 22868
#include <iostream>

#define MOD 1000000007

using namespace std;

int C[200005];
int pre[200005];
long dp[200005];

int main() {
    int n, c;
    cin >> n;
    dp[0] = 1;
    for(int i = 1; i <= n; ++i) {
        cin >> c;
        if (pre[c] > 0 && pre[c] != i - 1) {
            dp[i] = dp[i - 1] + dp[pre[c]];
            dp[i] %= MOD;
        } else {
            dp[i] = dp[i - 1];
        }
        pre[c] = i;
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define sum(x,y) que(1,1,n,x,y)
#define change(x,y,z) chan(1,1,n,x,y,z)
#define add(x,y,z) Plus(1,1,n,x,y,z)
#define mid (l+r>>1)
using namespace std;
long long sum[400000],fg[400000],ad[400000];
long long n,m,a,b; 
void down(int now,int l,int r)
{
	if(fg[now])
	{
		fg[now]+=ad[now];
		fg[now<<1]=fg[now];
		fg[now<<1|1]=fg[now];
		ad[now]=ad[now<<1]=ad[now<<1|1]=fg[now]=0;
		sum[now<<1]=fg[now<<1]*(mid-l+1);
		sum[now<<1|1]=fg[now<<1|1]*(r-mid);
	}
	if(ad[now])
	{
		ad[now<<1]+=ad[now];
		ad[now<<1|1]+=ad[now];
		sum[now<<1]+=ad[now]*(mid-l+1);
		sum[now<<1|1]+=ad[now]*(r-mid);
		ad[now]=0; 
	}
}
void updata(int now)
{
	sum[now]=sum[now<<1]+sum[now<<1|1];
}
void chan(int now,int l,int r,int x,int y,long long z)
{
	if(l==x && r==y)
	{
		fg[now]=z;
		ad[now]=0;
		sum[now]=z*(r-l+1);
		return;
	}
	down(now,l,r);
	if(x<=mid)
		chan(now<<1,l,mid,x,min(mid,y),z);
	if(y>mid)
		chan(now<<1|1,mid+1,r,max(mid+1,x),y,z);
	updata(now);
}
void Plus(int now,int l,int r,int x,int y,long long z)
{
	if(l==x && r==y)
	{
		ad[now]+=z;
		sum[now]+=z*(r-l+1);
		return;
	}
	down(now,l,r);
	if(x<=mid)
		Plus(now<<1,l,mid,x,min(mid,y),z);
	if(y>mid)
		Plus(now<<1|1,mid+1,r,max(mid+1,x),y,z);
	updata(now);
}
long long que(int now,int l,int r,int x,int y)
{
	if(l==x && r==y)
		return sum[now];
	down(now,l,r);
	long long ret=0;
	if(x<=mid)
		ret+=que(now<<1,l,mid,x,min(y,mid));
	if(y>mid)
		ret+=que(now<<1|1,mid+1,r,max(x,mid+1),y);
	return ret;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%lld",&a,&b);
		int l=1,r=a;
		for(;l<r;)
			if(sum(mid,mid)*(a-mid+1)-sum(mid,a)<=b)
				r=mid;
			else
				l=mid+1;
		b-=sum(l,l)*(a-l+1)-sum(l,a);
		change(l,a,sum(l,l));
		add(l,a,b/(a-l+1));
		if(b%(a-l+1))
		add(l,l+b%(a-l+1)-1,1);
	}
	for(int i=1;i<=n;i++)
		printf("%lld\n",sum(i,i));
	return 0;
}

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

const int inf = INT_MAX;

struct SegmentTree {
  size_t n;
  vector<int> v;

  SegmentTree(size_t size) : n(1 << (32 - __builtin_clz(size - 1))), v(2 * n - 1, inf) {}

  void update(int k, int x) {
    k += n - 1;
    v[k] = x;
    while (k) {
      k = (k - 1) / 2;
      v[k] = min(v[2 * k + 1], v[2 * k + 2]);
    }
  }

  int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return inf;
    if (a <= l && r <= b) return v[k];
    return min(query(a, b, 2 * k + 1, l, (l + r) / 2), query(a, b, 2 * k + 2, (l + r) / 2, r));
  }

  int query(int l, int r) {
    return query(l, r, 0, 0, n);
  }
};

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

  SegmentTree seg(n);
  while (q--) {
    int c, x, y;
    cin >> c >> x >> y;

    if (c) {
      cout << seg.query(x, y + 1) << endl;
    } else {
      seg.update(x, y);
    }
  }
}

Measured memory_bytes: 3832
# coding: utf-8
# Your code here!

num = int(raw_input())
length = len(str(num))
sum_of_num = sum(list(map(int,list(str(num)))))
max_of_num = int(str(num)[0])-1+(length-1)*9
print max(sum_of_num,max_of_num)

Measured memory_bytes: 2568
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    n: usize,
    a: [usize; n]
    }
    let mut s = a[1];
    for i in 2..n {
        s ^= a[i];
    }
    print!("{} ", s);
    for i in 1..n {
        print!("{} ", s ^ a[i] ^a[0])
    }
}


Measured memory_bytes: 6364
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

const int MAX_N = 2000001;

vector<int> graph[MAX_N];
int qs[MAX_N];
int rs[MAX_N];
bool visit[MAX_N];
int n,q;

void dfs(int v, int current) {
	if (visit[v]) return;
	visit[v] = true;
	auto currentScore = current + qs[v];
	rs[v] = currentScore;
	for (auto e : graph[v]) {
		dfs(e, currentScore);
	}
}

int main()
{
	cin >> n >> q;
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	for (int i = 0; i < q; i++) {
		int q, x;
		cin >> q >> x;
		q--;
		qs[q] += x;
	}
	dfs(0, 0);

	for (int i = 0; i < n; i++) {
		cout << rs[i] << " ";
	}
	return 0;
}


Measured memory_bytes: 69120
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <cmath>
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int ans = n;
    sort(a.begin(),a.end());
    int ap = a[0];
    int count = 0;
    vector<int> c;
    vector<int> c2;
    for(int i=0; i<n; i++){
        if(ap==a[i]){
            count += 1;
        }else{
            c.push_back(count);
            count = 1;
        }
        ap = a[i];
    }
    c.push_back(count);
    int bf = 0;
    int be = 0;
    for(int i=0; i<c.size(); i++){
        if(c[i]%2==1){
            ans -= (c[i]-1);
            c[i] = 1;
        }else{
            ans -= (c[i]-2);
            c[i] = 2;
            bf += 1;
        }
    }
    if(bf%2==1){
        ans -= (bf-1)+2;
    }else{
        ans -= bf;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1276
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(H: int, W: int, S: "List[str]"):

    table1 = [[0]*W for _ in range(H)]
    for h in range(H):
        for i, c in enumerate(S[h]):
            if c == "#":
                table1[h][i] = 0
            else:
                if i == 0:
                    table1[h][i] = 1
                else:
                    table1[h][i] = table1[h][i-1]+1
    # for h in range(H):
    #     print(table1[h])
    # print()
    for h in range(H):
        buf = 0
        for w in range(W-1, -1, -1):
            if table1[h][w] != 0:
                if buf == 0:
                    buf = table1[h][w]
                table1[h][w] = buf
            else:
                buf = 0
    # for h in range(H):
    #     print(table1[h])
    table2 = [[0]*W for _ in range(H)]
    for w in range(W):
        for h in range(H):
            c = S[h][w]
            if c == "#":
                table2[h][w] = 0
            else:
                if h == 0:
                    table2[h][w] = 1
                else:
                    table2[h][w] = table2[h-1][w]+1
    # for h in range(H):
    #     print(table2[h])
    for w in range(W):
        buf = 0
        for h in range(H-1, -1, -1):
            if table2[h][w] != 0:
                if buf == 0:
                    buf = table2[h][w]
                table2[h][w] = buf
            else:
                buf = 0
    # print()
    # for h in range(H):
        # print(table2[h])

    m = -INF
    for h in range(H):
        for w in range(W):
            buf = table1[h][w] + table2[h][w]
            if buf > m:
                m = buf
                # print(h, w)
    print(m-1)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(H)]  # type: "List[str]"
    solve(H, W, S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 122204
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

ll N , M;
ll num[100005];
bool posib[100005];
vector<ll> ans;

vector<pair<ll,ll> >op;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    rep(i, 100005) {
        num[i] = 1;
        posib[i] = false;
    }

    cin >> N >> M ;
    rep(i,M){
        ll x, y;
        cin >> x >> y;
        x--, y--;
        op.pb(mp(x,y));
    }
    
    
    posib[0] = true;
    
    rep(i,M){
        ll from = op[i].first;
        ll to = op[i].second;
        if(posib[from] == true) posib[to] = true;
        num[from] --;
        num[to] ++;
        if(num[from] == 0) posib[from] = false;
    }

    ll ans =  0;
    rep(i,N){
        if(posib[i]) cerr << i << ": true" << endl;
        else cerr << i << ": false" << endl;;
        if(posib[i]) ans ++;
    }

    cout << ans << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 3316
import sys
from pprint import pprint

def solve(N, people):
    n_red = 0
    n_blue = 0
    for i in xrange(len(people)):
        #print i, people[i]
        if people[i] == "R":
            n_red += 1
        elif people[i] == "B":
            n_blue += 1
        else:
            print "something wrong!"

    if n_red > n_blue:
        return "Yes"
    else:
        return "No"

if __name__ == '__main__':

    N = sys.stdin.readline().strip()
    people = sys.stdin.readline().strip()
    ans = solve(int(N), people)
    print ans

Measured memory_bytes: 2692
/*
700分的题就这么神仙了么。。好难啊。。。

先说结论吧

设$mx, mn$分别为最大 / 最小值，显然$mx - mn > 1$的时候无解

接下来分两种情况讨论

$mx = mn$：这时候每一种颜色要么是互不相同，要么是至少出现两次

$mx = mn +1$：这时候小的元素一定是独一无二的，大的元素至少出现两次。

以上结论都可以用反证法证明。


总结：
虽然结论证起来不难，但是自己想的话确实是太难受了，因为会有很多干扰你的模型(我最开始的时候还想tarjan缩点来着qwq)。
自己推了一个多小时也刚刚推除了无解的情况和$mx = mn$的情况，推到最后直接心态爆炸，我甚至都感觉自己的思路有问题，
因为每个结论要证明都不是很显然，总是感觉自己想复杂了。不过这题确实是好题
*/
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10, INF = 1e9 + 10;
inline int read() {
	char c = getchar(); int x = 0, f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
int N, a[MAXN];
main() {
	N = read();
	for(int i = 1; i <= N; i++) a[i] = read();
	sort(a + 1, a + N + 1);
	int mn = 0, mx = 0, num;
	a[0] = -1;
	for(int i = 1; i <= N; i++) 
		if(a[i] != a[i - 1]) {
			if(!mn) mn = a[i];
			else if(!mx) mx = a[i], num = i - 1;
			else {puts("No"); return 0;}
		}
	if(!mx) {
		if((mn == N - 1) || (mn * 2 <= N)) puts("Yes");
		else puts("No");
	} else {
		if((mx == mn + 1) && (2 * (mx - num) <= N - num) && (mx - num > 0)) puts("Yes");
		else puts("No");
	}
	return 0;
}
/*

*/


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,i=0,j,s,x[10000],min=1000000,goukei=0;
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> x[i];
    }
    for(i=0;i<105;i++)
    {
        goukei=0;
        for(j=0;j<n;j++)
        {
            goukei+=abs(x[j]-i)*abs(x[j]-i);
        }
        if(min>goukei)
        {
            min=goukei;
        }
    }
    cout << min << endl;
    return 0;

}


Measured memory_bytes: 3616
#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 a, b, c;
    cin >> a >> b >> c;

    if (c >= a && c <= b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

public class Main {
    static long INF = 1000000000;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        long[] a = new long[n];
        long min = INF;
        long cntMinus = 0;
        long ans = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
            if (a[i] < 0) {
                cntMinus++;
            }
            ans += Math.abs(a[i]);
            min = Math.min(min, Math.abs(a[i]));
        }
        if (cntMinus % 2 == 0) {
            System.out.println(ans);
            return;
        }
        System.out.println(ans - Math.abs(min) * 2);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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


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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    if (A <= C and B > C and B <= D) {
        cout << B - C << endl;
    } else if (A >= C and B <= D) {
        cout << B - A << endl;
    } else if (A < D and B >= D and A >= C) {
        cout << D - A << endl;
    } else if (A <= C and B >= D) {
        cout << D - C << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n,m;
    cin>>n>>m;
    ll k;
    cin>>k;
    char board[n+1][m+1];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>board[i][j];
        }
    }
    ll ans=0;
    for(int i=0;i<(1<<n);i++)
    {
        for(int j=0;j<(1<<m);j++)
        {
            int cnt=0;
            for(int x=0;x<n;x++)
            {
                for(int y=0;y<m;y++)
                {
                    if(((1<<x)&i)==0 && ((1<<y)&j)==0 && board[x][y]=='#')
                        cnt++;
                }
            }
            if(cnt==k)
                ans++;
        }
    }
    cout<<ans<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

const int INF = 0x3f3f3f3f;

class Edge{
public:
    int to, cap, rev;
    Edge(int _to, int _cap, int _rev): to(_to), cap(_cap), rev(_rev){};
};

class FordFulkerson{
public:
    vector<vector<Edge>> G;
    vector<bool> used;
    
    FordFulkerson(int n){
        G.resize(n);
        used.resize(n);
    }
    
    void add_edge(int from, int to, int cap){
        G[from].push_back(Edge(to, cap, G[to].size()));
        G[to].push_back(Edge(from, 0, G[from].size()-1));
    }
    
    int dfs(int v, int t, int f){
        if(v == t)
            return f;
        used[v] = true;
        for(int i=0; i<G[v].size(); i++){
            Edge& e = G[v][i];
            if(!used[e.to] && e.cap > 0){
                int d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    
    int max_flow(int s, int t){
        int res = 0;
        while(true){
            fill(used.begin(), used.end(), false);
            int f = dfs(s, t, INF);
            if(f == 0)
                return res;
            res += f;
        }
        return res;
    }
};


int N, M, S, T;

int main(){
    cin >> N >> M;
    FordFulkerson ff(N);
    set<pair<int, int>> revs;
    map<pair<int, int>, int> rtoi;
    
    for(int i=0; i<M; i++){
        int x, y;
        cin >> x >> y; x--; y--;
        ff.add_edge(x, y, 1);
        ff.add_edge(y, x, 1);
        
        revs.insert(make_pair(y, x));
        rtoi[make_pair(y, x)] = i+1;
    }
    cin >> S >> T;
    S--; T--;
    
    cout << ff.max_flow(S, T) << endl;
    
    set<pair<int, int>> edges;
    for(int u=0; u<N; u++){
        for(Edge edge: ff.G[u]){
            if(edge.cap == 0 && revs.find(make_pair(u, edge.to)) != revs.end()){
                edges.insert(make_pair(u, edge.to));
            }
        }
    }
    
    cout << edges.size() << endl;
    for(auto p: edges)
        cout << rtoi[p] << endl;
    
    return 0;
}

Measured memory_bytes: 3380
#Coding:Utf-8

N=int(input())
H=list(map(int,input().split()))
for i in reversed(range(1,N)):
    if H[i]>=H[i-1]:
        pass
    elif H[i]==H[i-1]-1:
        H[i-1]=H[i]
    else:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 14396
#define _USE_MATH_DEFINES 
#include <cmath>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<vector>
#define rep(i,start,n) for(int i=start;i<n;i++)
#define And &&
#define Or ||
#define Lb cout<<endl
using namespace std;

int main(void) {
	int n, x,sum;
	while(true){
		sum = 0;
		cin >> n >> x;
		if (n == 0 And x == 0)break;
		for (int i = 1; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				int r = x - i - j;
				if (j < r And r <= n) sum++;
			}
		}
		cout << sum << endl;
	}
}

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

int main(){
  long long N;
  cin>>N;
  vector<long long> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  long long ans=0;
  int flag=1;
  int temp=0;
  for(int i=1;i<N;i++){
    ans+=A[temp];
    if(flag==1){
      temp++;
      flag=0;
    }
    else{
      flag=1;
    }
    //cout<<i<<" "<<ans<<endl;
  }
  cout<<setprecision(20)<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4848
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        int min = 1000000000;
        int dif = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if (a < min) {
                min = a;
            } else if (dif == a - min) {
                ans++;
            } else if (dif < a - min) {
                dif = a - min;
                ans = 1;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 48204
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int A=scan.nextInt();
    int B=scan.nextInt();
    int count=0;
    int consent=1;
    while(consent<B){
      consent--;
      consent+=A;
      count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define double long double
#define M_PI 3.14159265358979323846 
const int mod = 1e9 + 7;

int32_t main()
{
    fastio;

    int x, y; cin >> x >> y;
    int b = (y-2*x)/2;
    int a = x - b;
    bool flag = true;
    if(a < 0 || b < 0 || 2*a + 4*b != y){
        flag = false;
    }

    cout << (flag?"Yes":"No") << endl;
    return 0;
}

/*
2x + 4y= legs
x + y = total

*/

Measured memory_bytes: 3660
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf 2000000000
#define EPS 1e-7
#define MOD 999377ll
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;
typedef pair<int, int> pr;
typedef pair<pair<ll, ll>, pair<ll, ll>> tup;

inline void solve()
{
	int h, n;
	cin >> h >> n;
	vector<pr> v(n);
	fore(i, 0, n)
		cin >> v[i].first >> v[i].second;
	vector<int> dp(h + 20000, inf);
	dp[0] = 0;

	fore(p, 0, n)
	{
		fore(i, 0, h)
		{
			if (dp[i] != inf)
			{
				dp[i + v[p].first] = min(dp[i + v[p].first], dp[i] + v[p].second);
			}
		}
	}

	int otv = inf;
	fore(i, h, dp.size())
		otv = min(otv, dp[i]);
	cout << otv;
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
}

Measured memory_bytes: 384
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<set>
#include<vector>
#define INF 100000000

#define MAX_N 100

typedef long long int ll;
using namespace std;


int main(){

	for(int i = 1; i <= 9; i++){
		for(int j = 1; j <= 9; j++){
			printf("%dx%d=%d\n", i, j, i*j);
		}
	}

	return 0;

}

Measured memory_bytes: 1096
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Debug.Trace

main :: IO ()
main = readLine >>= print . solve

solve :: [Int] -> Double
solve [n, k] = sum $ map calc [1..n]
    where
        calc x
            | x < k = 1 / c 
            | otherwise = 1 / fromIntegral n
            where
                c = (* (fromIntegral n)) . (2 ^) . fromIntegral . ceiling . logBase 2 $ fromIntegral k / fromIntegral x

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 892
#!/bin/env python

INF = 1e9

def main():
    N = int(raw_input())
    sum = 0
    tmp = INF
    for i in xrange(N):
        s = int(raw_input())
        sum += s
        if s % 10 != 0:
            tmp = min(tmp, s)
    if sum % 10 != 0:
        print sum
    elif tmp != INF:
        print sum - tmp
    else:
        print 0

if __name__ == '__main__':
    main()

Measured memory_bytes: 2568
import java.util.Scanner;

public class Main {
    // Round by 3 digits
    static float roundUp(float value) {
        float mod = value % 1000;
        if (mod > 0) {
            value = value + (1000 - mod);
        }
        return value;
    }

    public static void main(String[] args) {
        float gankin = 100_000f;
        Scanner sc = new Scanner(System.in);
        int nweek = sc.nextInt();
        float debt = gankin;
        for (int i = 0; i < nweek; i++) {
            debt = roundUp(debt * 1.05f);
        }
        System.out.printf("%d\n", Math.round(debt));
    }
}

Measured memory_bytes: 25992
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

	int n; cin >> n;
	vector<ll> a(n);
	int two = 0, four = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 4 == 0) four++;
		else if (a[i] % 2 == 0) two++;
	}
	if ((four * 2 + two >= n)|| (!two&&four*2+1>=n)) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
  int n,x;
  while(1){
    scanf("%d %d",&n ,&x);
    if(n==0&&x==0)break;
    int sum=0;
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
        for(int k=j+1;k<=n;k++){
          if(i+j+k==x){
            sum++;
          }
        }
      }
    }
    printf("%d\n",sum);
  }
}



Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    vector<int> L(n);
    rep(i,n) cin>>L[i];

    sort(all(L));
    ll ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int k=lower_bound(all(L),L[i]+L[j])-L.begin();
            ans+=max(k-(j+1),0);
        }
    }

    cout<<ans<<endl;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;


int main(){
    int A,P;
    cin >> A >> P;
    P = P + 3*A;
    cout << P/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;

int N;

double dp(vector<vector<vector<double>>> &memo,int i,int j,int k){
  if(memo.at(i).at(j).at(k)>=0)  return memo.at(i).at(j).at(k);

  memo.at(i).at(j).at(k)=N;
  if(i-1>=0)  memo.at(i).at(j).at(k)+=dp(memo,i-1,j,k)*i;
  if(i+1<=N && j-1>=0)  memo.at(i).at(j).at(k)+=dp(memo,i+1,j-1,k)*j;
  if(j+1<=N && k-1>=0)  memo.at(i).at(j).at(k)+=dp(memo,i,j+1,k-1)*k;
  memo.at(i).at(j).at(k)/=(double)(i+j+k);

  return memo.at(i).at(j).at(k);
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  cout << fixed << setprecision(15);
  cin >> N;
  vector<int> cnt(4,0);
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    cnt.at(a)++;
  }

  vector<vector<vector<double>>> memo(N+1,vector<vector<double>>(N+1,vector<double>(N+1,-1)));
  memo.at(0).at(0).at(0)=0;
  cout << dp(memo,cnt.at(1),cnt.at(2),cnt.at(3)) << endl;
  /*
   for(int i=0;i<=N;i++){
    for(int j=0;j<=N;j++){
      for(int k=0;k<=N;k++){
        cout << i << "," << j << "," << k << "," << memo.at(i).at(j).at(k) << endl;
      }
    }
  }*/

  return 0;
}

Measured memory_bytes: 216960
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, modinv, bitSearch, bitList, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color; vll path; vl D; ll C;
//***********//
int main() {
	cin >> N >> M;
	vl A(N);
	ll sum = 0;
	for (i = 0; i < N; i++) {
		cin >> A[i];
		sum += A[i];
	}
	ll pre = 0;
	for (i = 0; i < N; i++) {
		if (A[i] * M * 4 >= sum) {
			pre++;
		}
	}
	if (pre >= M) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

public class Program000
{
    public static void Main(string[] args)
    {
        var r = new char[3];
        var s = Console.ReadLine();
        if (s[0]=='1')
        {
            r[0] = '9';
        }
        else
        {
            r[0] = '1';
        }


        if (s[1] == '1')
        {
            r[1] = '9';
        }
        else
        {
            r[1] = '1';
        }


        if (s[2] == '1')
        {
            r[2] ='9';
        }
        else
        {
            r[2] = '1';
        }

        Console.WriteLine(new String(r));

    } // Main
}     // Class



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

using db = double;
using ll = long long;
using vi = vector <int>;
#define pb push_back

const int N = 13;
int l[N];

int main() {
	ios :: sync_with_stdio(0);

	while(cin >> l[1]) {
		char c;
		for(int i = 2; i <= 10; i ++)
			cin >> c >> l[i];
		int v1, v2; cin >> c >> v1 >> c >> v2;
		partial_sum(l, l + 11, l);
		for(int i = 1; i <= 10; i ++)
			if(l[i - 1] * (v1 + v2) < l[10] * v1 && l[10] * v1 <= l[i] * (v1 + v2))
				cout << i << '\n';
	}

	return 0;
}

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

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

    int t;
    t=1;

    while(t--){
        string n;
        cin>>n;

        int len=n.length();
        int ans=0;
        for(int i=0;i<len;i++){
            ans+=n[i]-'0';
        }

        if(ans%9==0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}





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

using namespace std;

vector<string> ans;
int n;

void dfs(string S, char ma){
    if (n == S.size()){
        ans.push_back(S);
        return;
    }

    for (char c = 'a'; c <= ma + 1; c++){
        dfs(S + c, max(ma, c));
    }
}

int main(){
    cin >> n;
    dfs("a", 'a');
    sort(ans.begin(), ans.end());
    for (const auto &s: ans)
        cout << s << endl;
}

Measured memory_bytes: 7796
#include <iostream>
#include <string>

using namespace std;

using std::string;

int main()
{
    string a;
    cin >> a;

    bool isPlayable = true;

    for (int i = 1; i <= a.length(); i++)
    {
        if ((i % 2) == 0)
        {
            if (a[i - 1] == 'R')
            {
                isPlayable = false;
                break;
            }
        }
        else
        {
            if (a[i - 1] == 'L')
            {
                isPlayable = false;
                break;
            }
        }
    }

    if (isPlayable)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3560
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	input = input.map(e => toIntArr(e.split(' ')));
	var d = input[0][0];
	var cs = input[1];
	var ss = input.slice(2);
	//var ts = input.slice(d+2).map(e=>e[0]);
	
	var score = 0;
	var ans = [];
	let type;
	var lastday = [];
	lastday.length = 26;
	lastday.fill(-1);

	//let scoreDay = [];

	//day(0~25)にtype(1~26)を選んだ場合の満足度の変化(lastdayのdayは0~)
	function getScore(day,type,lastday){
		let ans = 0;
		ans += ss[day][type-1];
		for(let t = 0; t < 26; t++){
			if(t!==type-1) ans -= cs[t] * (day - lastday[t]);
		}
		return ans;
	}

	let d3 = Math.floor(d/3);
	let rest = d - d3*3;

	var tempScore; // [[t0,t1,t2,score],...]
	var tempLastday;
	let subScore;

	for(let i = 0; i < d3; i++){
		tempScore = [];

		for(let t0 = 0; t0 < 26; t0++){
			tempLastday = lastday.concat();
			subScore = 0;

			tempLastday[t0] = i*3;
			subScore += getScore(i*3,t0+1,tempLastday);
			for(let t1 = 0; t1 < 26; t1++){
				tempLastday[t1] = i*3 +1;
				subScore += getScore(i*3+1,t1+1,tempLastday);
				for(let t2 = 0; t2 < 26; t2++){
					tempLastday[t2] = i*3 +2;
					subScore += getScore(i*3+2,t2+1,tempLastday);
					tempScore.push([t0,t1,t2,subScore]);
					}
				}
			}

		//console.log(tempScore)
		let want = tempScore.map(e=>e[3]).indexOf(Math.max(...tempScore.map(e=>e[3])));
		let want2 = tempScore[want];
		//console.log(want,want2)
		ans.push(want2[0]+1,want2[1]+1,want2[2]+1);
		lastday[want2[0]] = i*3;
		lastday[want2[1]] = i*3+1;
		lastday[want2[2]] = i*3+2;

	}

	for(let i = d3*3; i < d; i++){
		tempScore = [];

		for(let j = 0; j < 26; j++){
			tempScore[j] = getScore(i,j+1,lastday);
		}

		let want = tempScore.indexOf(Math.max(...tempScore));
		ans.push(want+1);
		lastday[want] = i;

	}

	console.log(ans.join('\n'));
}

//a.indexOf(Math.max(...a))

Measured memory_bytes: 57956
import java.util.Scanner;

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

    while(true){
        int H = sc.nextInt();
        int W = sc.nextInt();

        if(H == 0 && W == 0)
           break;

        for(int i = 1;i<=H;i++){
            if(i==1||i==H){
                  for(int j = 1;j <= W;j++){
                        System.out.printf("#");
                  }
                        System.out.printf("\n");
            }else{
                  for(int j = 1;j<=W;j++){
                      if(j==1||j==W){
                          System.out.printf("#");
                      }else{
                          System.out.printf(".");
                      }
                  }
                      System.out.printf("\n");
            }
        }
                System.out.printf("\n");
    }
  }
}



Measured memory_bytes: 58448
n = int(input())
c = list(input())#ciが R のとき赤、W のとき白
a = c.count("R")
b = 0
count = max(a, b)
# a: R->W, b: W->Rの回数
for i in range(n):
  if c[i] == "R":
    a = a - 1
  else:
    b = b + 1
  ans = max(a, b)
  count = min(ans, count)
print(count)
 

Measured memory_bytes: 10708
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cctype>
#include <algorithm>
using namespace std;

int ret;
int s;

void dfs(int begin, int depth, int sum){
    int i;
    if (depth == 0){
	if (s == sum) ret++;
	return;
    }
    for (i = begin+1; i <= 9; i++){
	dfs(i, depth-1, sum+i);
    }
}

int main(){
    int n;
    int i;
    while (cin >> n >> s, n || s){
	for (i = 0; i <= 9; i++){
	    dfs(i, n-1, i);
	}
	cout << ret << endl;
	ret = 0;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    vector<ll> z(n);
    for (int i = 0; i < n; i++) {
        cin >> z[i];
    }
    vector<ll> sa(n);
    vector<ll> wa(n);
    for (int i = 0; i < n; i++) {
        sa[i] = i - z[i];
    }
    for (int i = 0; i < n; i++) {
        wa[i] = i + z[i];
    }
    sort(sa.begin(), sa.end());
    sort(wa.begin(), wa.end());
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ll ok = -1;
        ll ng = n;
        while(ng - ok>1){
            ll mid = (ok + ng) / 2;
            if (wa[mid] <= sa[i])ok = mid;
            else ng = mid;
        }
        ll ook = -1;
        ll nng = n;
        while (nng - ook > 1) {
            ll mid = (ook + nng) / 2;
            if (wa[mid] < sa[i])ook = mid;
            else nng = mid;
        }
        ans += ok - ook;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8020
#include <iostream>

using namespace std;

int main() {
	
	int n = 0;

	char s[4];
	for (int i = 0; i < 4; i++) {
		cin >> s[i];
		if (s[i] == '+') {
			n += 1;
		}
		else if (s[i] == '-') {
			n -= 1;
		}
	}

	cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF = (1LL<<60)-1;
const int maxN = 1000001;
int32_t main(){
    SPEED;
    int d, t, s;
    cin >> d >> t >> s;
    double ans = double(d) / double(s);
    int t1 = ceil(ans);
    if(t1 <= t) cout << "Yes" ;
    else cout << "No" ;
}

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

typedef long long ll;

using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N, A, B;
int main(){
    fastStream();
    cin >> N >> A >> B;
    cout << min(A, B) << " ";
    if(A + B <= N){
        cout << 0 << endl;
    }
    else{
        cout << A + B - N << endl;
    }
    

    return 0;
}


Measured memory_bytes: 892
#include<stdio.h>
long long MAX(long long a,long long b){return a<b?b:a;}
long long n,m,i,j,a,b,d[110][100010]={};
int main(){
  scanf("%lld %lld",&n,&m);
  for(i=0;i<n;i++){
    scanf("%lld %lld",&a,&b);
    for(j=0;j<m;j++){
      //printf("%lld ",d[i][j]);
      d[i+1][j]=MAX(d[i+1][j],d[i][j]);
      if(j+a<=m)d[i+1][j+a]=MAX(d[i+1][j+a],d[i][j]+b);
    }//printf("%d\n",d[i][m]);      
  }
  //for(i=0;i<=m;i++)printf("%d ",d[n][i]);printf("\n");
  for(i=j=0;i<=m;i++)j=MAX(j,d[n][i]);
  printf("%lld\n",j);
  return 0;
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,ans;
vector<pair<int,int>> vec;

int keta(int x){
	int ansk=0;
	while(x>=1){
		x/=10;
		ansk++;
	}
	return ansk;
}

signed main(){
	ans=1000000000;
	cin>>n;
	for(int i=1;i<=sqrt(n)+1;i++){
		if(n%i==0){
			vec.push_back({i,n/i});
		}
	}
	for(int i=0;i<vec.size();i++){
		ans=min(ans,max(keta(vec[i].first),keta(vec[i].second)));
	}
	cout<<ans<<endl;
	
}


Measured memory_bytes: 256
n = int(input())
mod = 10 ** 9 + 7
c = list(map(int, input().split()))
c.sort()

ans = 0
for i in range(n):
    if i < n - 1:
        ans += c[i] * (n - i + 1) * pow(2, n - i - 2, mod) * pow(2, i, mod)
        ans %= mod

    else:
        ans += c[i] * pow(2, n - i - 1, mod) * pow(2, i, mod)
        ans %= mod


ans *= pow(2, n, mod)
ans %= mod

print(ans)

Measured memory_bytes: 26172
N, K = map(int,input().split())

x = list(map(int,input().split()))


xpl = []
xmi = []

for i in x:

    if i == 0:
        N -= 1
        K -= 1

    elif i < 0:
        xmi.append(-i)

    elif i > 0:
        xpl.append(i)

xmi.sort()


if K == 0:
    ans = 0

elif len(xmi) == 0:

    ans = xpl[K - 1]

elif len(xpl) == 0:

    ans = xmi[K - 1]

else:

   npl = K
   nmi = 0
   ans = -1

   while npl >= 0:

        if npl <= len(xpl) and nmi <= len(xmi):

           leng = max(xpl[npl-1],xmi[nmi-1]) + 2 * min(xpl[npl-1],xmi[nmi-1])

           if ans < 0  or  ans > leng:
               ans = leng

        npl -= 1
        nmi += 1

print (ans)


Measured memory_bytes: 14480
S=input()

ans = 0
N = len(S)
if N==1:ans = 1
elif N==2:
    if S[0]==S[1]:ans=1
    else:ans=2
else:
    for i in range(1,3):
        s = [S[0:i]]
        while i<N:
            if s[-1] == S[i]:
                s.append(S[i:i+2])
                i+=2
            else:
                s.append(S[i])
                i+=1
        if s[-1]==s[-2]:
            s[-2] += s[-1]
            s.pop()
            if s[-1]==s[-2]:
                s[-2] += s[-1][0]
                s[-1] = s[-1][1]
        ans = max(ans,len(s))
print(ans)

Measured memory_bytes: 8064