akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;
using System.Text;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var N = consoleReader.Int;
            var a = consoleReader.Split.Int;

            long count = 0;
            int l = 0;
            int current = 0;
            for (int r = 0; r < a.Length; r++)
            {
                while (l < r && (a[r] & current) != 0) current ^= a[l++];
                current ^= a[r];
                count += r - l + 1;
            }

            return count;
        }

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }
#pragma warning disable
    public class ConsoleReader
    {
        private string[] line = Array.Empty<string>();
        private int linePosition;
        private TextReader textReader;
        public ConsoleReader(TextReader tr) { textReader = tr; }
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
        public string String
        {
            get
            {
                if (linePosition >= line.Length)
                {
                    linePosition = 0;
                    line = textReader.ReadLine().Split();
                }
                return line[linePosition++];
            }
        }
        public class SplitLine
        {
            private string[] splited;
            public SplitLine(ConsoleReader cr) { splited = cr.textReader.ReadLine().Split(); }
            public int[] Int => String.Select(x => int.Parse(x)).ToArray();
            public long[] Long => String.Select(x => long.Parse(x)).ToArray();
            public double[] Double => String.Select(x => double.Parse(x)).ToArray();
            public string[] String => splited;
        }
        public SplitLine Split => new SplitLine(this);
        public class RepeatReader
        {
            ConsoleReader cr; int count;
            public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; }
            public IEnumerable<T> Select<T>(Func<ConsoleReader, T> func) { for (int i = 0; i < count; i++) yield return func(cr); }
            public IEnumerable<string> String { get { for (int i = 0; i < count; i++) yield return cr.String; } }
            public IEnumerable<int> Int { get { for (int i = 0; i < count; i++) yield return cr.Int; } }
            public IEnumerable<double> Double { get { for (int i = 0; i < count; i++) yield return cr.Double; } }
        }
        public RepeatReader Repeat(int count) => new RepeatReader(this, count);
    }
}

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

int maxi(int t[],int n,int pos)
{
    int  m;
    if(pos==0) m=t[1];
    else m=t[0];
    for(int i=0;i<n;i++)
    {
        if((i!=pos)&&(t[i]>m))
        m=t[i];
    }
    return m;
}
int main ()
{
    int n,im;
    cin>>n;
    int a[n];
    cin>>a[0];
    im=0;
    for(int i=1;i<n;i++)
    {
           cin>>a[i];
           if(a[i]>a[im])
            im=i;
    }

    for(int i=0;i<n;i++)
    {
        if(i!=im)
            cout<<a[im]<<endl;
        else
        cout<<maxi(a,n,i)<<endl;
    }
    return 0;
}

Measured memory_bytes: 2432
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
#include <cassert>
using namespace std;

bool sosu(int n){
    bool flag = true;
    for(int i = 2; i < sqrt(n)+1; i++){
        if(n%i == 0){
            flag = false;
            break;
        }
    }
    return flag;
}

 
int main(){
    int x;
    cin >> x;
    if(x==2){
        cout << 2 << endl;
        return 0;
    }
    bool flag2  =true;
    while(flag2){
        flag2 = !sosu(x);
        x++;
    }
    x--;
    cout << x << endl;
}

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

using namespace std;
using ll = long long;
const int MOD=1000000007;

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

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

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



int main(int argc, char**argv){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++){
      cin >> a[i];
      a[i]--;
    }
    int cnt = 0;
    int ans = 0;
    int light = 0;
    while (cnt < n){
        light = a[light];
        ans++;
        if (light == 1) break;
        cnt++;
    }
    if (cnt == n) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define For(i, a, b) for (int i = int(a); i < int(b); i++)
#define Dor(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define Foz(i, a) For(i, 0, a)
#define Doz(i, a) Dor(i, 0, a)
#define Trav(e, v) for (auto& e : v)
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<ii>;
template <typename T> bool ckmin (T& a, T b) { return (b < a) ? a = b, 1 : 0; }
template <typename T> bool ckmax (T& a, T b) { return (b > a) ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
	string s = "[ ";
	for (auto& x : e) s += to_string(x) + " ";
	return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
	return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
 	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
const int N = 100010;
int a[N], p[N], s[N], n;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	cin >> n;
	For(i, 1, n + 1) cin >> a[i];
	a[0] = a[n + 1] = p[0] = s[n + 1] = 0;
	For(i, 1, n + 1) p[i] = p[i - 1] + abs(a[i] - a[i - 1]);
	Dor(i, 1, n + 1) s[i] = s[i + 1] + abs(a[i] - a[i + 1]);
	For(i, 1, n + 1) cout << p[i - 1] + s[i + 1] + abs(a[i - 1] - a[i + 1]) << '\n';
}



Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <cstring>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <functional>
#include <ctime>
#include <unordered_map>
#include <sstream>

using namespace std;
typedef long long Long;
typedef long double Double;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
typedef pair<Long,Long> PLL;

int read(int &x) { return scanf("%d", &x); }
int read(int &x, int &y) { return scanf("%d%d", &x, &y); }
int read(int &x, int &y, int &z) { return scanf("%d%d%d", &x, &y, &z); }
int read(Long &x) { return scanf("%lld", &x); }
int read(Long &x, Long &y) { return scanf("%lld%lld", &x, &y); }
int read(double &x) { return scanf("%lf", &x); }
char buff[2000010];
int read(string &s) { int r = scanf("%s", buff); s = buff; return r; }

#define dlog2(n) ((n) == -1 ? 0 : (31-__builtin_clz(n)))

#define sz(a) int(a.size())

struct Math
{
	typedef long long Long;
	static int egcd(int a, int b){
		int x,y;
		return egcd(a,b,x,y);
	}
	// ax + by = c
	static int egcd(int a,int b, int &x, int &y) {
		x = 1, y = 0;
		int nx = 0, ny = 1;
		int nr = b, r = a;
		while(nr != 0) {
			int q = r / nr;
			tie(r, nr) = make_tuple(nr, r - q*nr);
			tie(x, nx) = make_tuple(nx, x - q*nx);
			tie(y, ny) = make_tuple(ny, y - q*ny);
		}
		// bezout = x , y
		// gcd    = o_r
		return r;
	}
	static int MOD;
	static Long modInv(Long a, Long b)
	{
		int x,y; egcd(a,b,x,y);
		return x < 0 ? x + b : x;
	}
	static Long divide(Long a, Long b)
	{
		return a * modInv(b, MOD) % MOD;
	}
	static int fact(int n)
	{
		static vector<int> F;
		if(F.size() <= n)
		{
			int oSZ = F.size();
			F.resize(n+1);
			if(oSZ == 0)F[0] = 1 , oSZ++;
			for(int i = oSZ; i <= n; ++i)
				F[i] = (1LL * F[i-1] * i) % MOD;
		}
		return F[n];
	}
	static int catalan(int n)
	{
		return divide(ncr(2*n,n), n+1);
	}
	static int ncr(int n,int k)
	{
		if(k < 0 || n < 0 || n < k)return 0;
		return divide(fact(n) , (1LL * fact(k) * fact(n-k)) % MOD);
	}
	static int mul(int a,int b){
		return (1LL*(a%MOD)*(b%MOD))%MOD;
	}
	static int  mul(int a,int b,int c){
		return (1LL*mul(a,b)*(c%MOD))%MOD;
	}
	static int  mul(int a,int b,int c,int d){
		return (1LL*mul(a,b)*mul(c,d))%MOD;
	}
	static bool solveDiophantine(int a, int b, int c, int &x, int &y) {
		int gc = egcd(a,b,x,y);
		if(c % gc != 0)return false;
		int d = c / gc;
		x *= d;
		y *= d;
		return true;
	}
	static void moveBezout(int a,int b, int c, int &x, int &y, int pos = 1){
		int gc = egcd(a,b);
		b /= gc;
		a /= gc;
		x += b * pos;
		y -= a * pos;
	}
};
int Math::MOD = 1000000007;

int main() {

	int N;
	read(N);
	string s;
	read(s);
	if (N % 2 == 0 && s.substr(0, N/2) + s.substr(0, N/2) == s) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

}
























Measured memory_bytes: 256
using System;
using System.Linq;

namespace _0094
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(x[0] * x[1] / 3.305785);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CBuildStairs solver = new CBuildStairs();
        solver.solve(1, in, out);
        out.close();
    }

    static class CBuildStairs {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt();
            int[] a = new int[n];
            a[0] = s.nextInt();
            for (int i = 1; i < n; i++) {
                a[i] = s.nextInt();
            }
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) a[i - 1]--;
            }
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    w.println("No");
                    return;
                }
            }
            w.println("Yes");
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define M 1000000007
ll n;
char s[500005];
ll dp[500005];
int p[500005],q[500005];
int main(void){
    cin>>n>>s;
    for(int i=0;i<n;i++){
        if(i>0)p[i]=p[i-1];
        if(s[i]=='0')p[i]=i;
    }
    q[n-1]=n-1;
    for(int i=n-1;i>=0;i--){
        if(i<n-1)q[i]=q[i+1];
        if(s[i]=='0')q[i]=i;
    }
    for(int i=0;i<n;i++){
        dp[i+1]=max(dp[i+1],dp[i]);
        int j=p[i];
        if(0<j&&j<i&&s[j-1]=='1')dp[i+1]=max(dp[i+1],dp[j-1]+i-j);
        j=q[i];
        if(j<n-1&&j>i&&s[j+1]=='1')dp[j+2]=max(dp[j+2],dp[i]+j-i);
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 8576
n = int(input())
f = [int(''.join(input().split()), 2) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
print(max(
    sum(p[i][sum(map(int, bin(b & f[i])[2:]))] for i in range(n))
    for b in range(1, 2**10)))

Measured memory_bytes: 3064
def gcd(m, n)
    if m < n 
        gcd(n, m)
    elsif n == 0
        m
    else
        gcd(n, m % n)
    end 
end

while gets
    x, y = $_.split.map(&:to_i)
    g = gcd(x, y)
    puts [g, x * y / g].join(" ")
end

Measured memory_bytes: 6100
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int a, b;
    cin >> a >> b;
    if ((a*b)%2==0){
        cout << "Even" << endl;
    } else {
        cout << "Odd" << endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i,N) repf(i,0,N)
#define reps(i,N) repfs(i,1,N)
#define repf(i,a,b) for(int i=a;i<b;i++)
#define repfs(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,N) for(int i=N-1;i>=0;i--)
#define reprs(i,N) for(int i=N;i>0;i--)
#define pb push_back
#define pob pop_back

template<typename T> 
void chmax(T &a,T b){ a = max(a, b);};
template<typename T> 
void chmin(T &a,T b){ a = min(a, b);};

typedef long long ll;
typedef pair<int,int> P;
const int INF = 1000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int n,k;
int h[200000];

void solve(){
	sort(h,h+n);
	int ans=INF;
	rep(i,n-k+1){
		chmin(ans, h[i+k-1]-h[i]);
	}
	cout<<ans<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>n>>k;
	rep(i,n) {
		cin>>h[i];
	}
		solve();
	return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;

int main()
{
    fast;
    
 ll n;
 cin>>n;
 ll a=0,b=0;
 for(ll i=0,x,y;i<n;i++)
 {
 	cin>>x>>y;
 	
 	
 	if(i==0)
 	{
 		a=x,b=y;
 		continue;
	 }
	
	
	ll x1,y1;
	x1=ceil((long double)a/(long double)x);
	y1=ceil((long double)b/(long double)y);
	
	ll curl=max(x1,y1);

	//cout<<curl<<"\n";
	a=x*curl;
	b=y*curl;
 	
 }
 
 
 
 cout<<a+b;
    
   
}

		
	
	
	
	


Measured memory_bytes: 3620
N = gets.chomp.to_i
str = gets.split
d = Array.new(N)
for i in 0...N do
    d[i] = str[i].to_i
end

answer = 0
for i in 0...N-1 do
    for j in i+1...N do
        answer += d[i] * d[j]
    end
end
puts answer

Measured memory_bytes: 1788
#include<cstdio>
#include<algorithm>
using namespace std;
int a[3],ans;
int main()
{
	scanf("%d%d%d",&a[0],&a[1],&a[2]);
	while(a[0]!=a[1]||a[1]!=a[2])
	{
		ans++;
		sort(a,a+3);
		if(a[2]-a[0]>=2)
			a[0]+=2;
		else
			a[0]++,a[1]++;
	}
	printf("%d",ans);
}

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

typedef long long ll;

ll p[20];
ll n,m;

int pop(int x) {
  int n = 0;
  while(x != 0) {
    n++;
    x &= (x-1);
  }
  return n;
}

int gcd(int x,int y) {
    if(y == 0) return x;
    return gcd(y,x%y);
}

ll lcm(ll x,ll y) {
    return x/gcd(x,y)*y;
}

ll calc2(ll i,ll n) {
    ll lc = 1;
    for(int k=0; k<m; ++k)
        if((i>>k)&1) lc = lcm(lc,p[k]);
//    cout<<"calc2 "<<i<<" "<<lc<<endl;
    return n/lc;
}

ll calc(ll i,ll n) {
    ll c2 = calc2(i,n);
    c2 = c2*(c2+1)/2;

    ll lc = 1;
    for(int k=0; k<m; ++k)
        if((i>>k)&1) lc = lcm(lc,p[k]);

//    cout<<"calc1 "<<c2<<" "<<lc<<endl;
    return lc*c2;
}


int main() {
    while(true) {
        cin>>n>>m;
        if(n == 0 && m == 0) break;
        for(int i=0; i<m; ++i) cin>>p[i];

        ll ans = n*(n+1)/2, at = n;
        for(ll i=1; i<(1<<m); ++i) {
            ll tmp = calc(i,n);
            ll tmp2 = calc2(i,n);
            if(pop(i)%2) {
                ans -= tmp;
                at -= tmp2;
            }else{
                ans += tmp;
                at += tmp2;
            }
        }

        if(at == 0) {
            printf("%.12f\n", 0.0);
        }else{
            double aa = (double)ans/at;
            printf("%.12f\n", aa);
        }
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 5000
#define MOD 1000000007

int main(){
  ll N,K;
  cin>>N>>K;
  ll ans=0;
  if(K==0){
    cout<<N*N<<endl;
  }else{
    for(ll b=K+1;b<=N;b++){
      ll x=N/b;
      ans+=x*(b-K);
      ans+=max<ll>(0,N-b*x-K+1);
    }
    cout<<ans<<endl;
  }
}


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


int main() {
    int a, b;
    cin >> a >> b;
    string s;
    if (a>b) s = "a > b";
    else if (a<b) s = "a < b";
    else s = "a == b";
    
    cout << s << endl;
}


Measured memory_bytes: 3136
# https://onlinejudge.u-aizu.ac.jp/problems/DPL_1_B


if __name__ == "__main__":
    N, W = list(map(int, input().split()))
    bag = []
    for _ in range(N):
        v, w = list(map(int, input().split()))
        bag.append((v, w))

    d = {}

    dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

    for i in range(N):
        for w in range(W+1):
            iv, iw = bag[i]
            if w >= iw:
                dp[i+1][w] = max(dp[i][w-iw] + iv, dp[i][w])
            else:
                dp[i+1][w] = dp[i][w]

    print(max(dp[N]))



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

signed main(){
	string s; cin >> s;
	int n = s.size();
	int num = s[0] - '0';
    bool check = false;
    for(int i = 1; i < n; i++) if(s[i] != '9') check = true;
	if(check) cout << num + 9 * (n - 1) - 1 << endl;
  else cout << num + 9 * (n -1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void ensure(bool exp) {
    if (!exp) {
        cout << -1 << endl;
        exit(0);
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<long long> d(n);
    map<long long, int> ver;
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
        ver[d[i]] = i;
    }
    vector<int> p(n);
    iota(p.begin(), p.end(), 0);
    sort(p.begin(), p.end(), [&](int i, int j) {
        return d[i] < d[j];
    });
    vector<int> sz(n, 1), parent(n, -1);
    vector<long long> f(n);
    for (int i = n - 1; i >= 1; --i) {
        int u = p[i];
        long long dp = d[u] - n + 2 * sz[u];
        ensure(dp < d[u]);
        ensure(ver.count(dp) > 0);
        parent[u] = ver[dp];
        sz[parent[u]] += sz[u];
        f[parent[u]] += f[u] + sz[u];
    }
    ensure(f[p[0]] == d[p[0]]);
    for (int i = 1; i < n; ++i)
        cout << parent[p[i]] + 1 << " " << p[i] + 1 << "\n";
    return 0;
}

Measured memory_bytes: 10496
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n , m;
    cin >> n >> m;
    if( abs( n - m ) < 2 ) {
        if( n == m ) {
            ll a = 1;
            for( int i = 1 ; i <= n ; i++ ) {
                a = a * i % 1000000007;
            }
            cout << 2 * a * a % 1000000007;
        } else {
            ll a = 1 , b = 1;
            for( int i = 1 ; i <= n ; i++ ) {
                a = a * i % 1000000007;
            }
            for( int i = 1 ; i <= m ; i++ ) {
                b = b * i % 1000000007;
            }
            cout << a * b % 1000000007;
        }
    } else cout << 0;
}





Measured memory_bytes: 256
from itertools import permutations

n, m = map(int, input().split())
graph = [set(map(lambda n: int(n) - 1, input().split())) for _ in range(m)]

print(sum(all(({0, per[i]} if not i else {per[i - 1], per[i]}) in graph for i in range(n - 1)) for per in permutations(i for i in range(1, n))))


Measured memory_bytes: 3060
package main

import "fmt"

func main() {
	var n, d, x int
	fmt.Scan(&n, &d, &x)
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
	}

	var cnt int
	for i := 1; i <= d; i++ {
		for _, a := range as {
			if (i-1)%a == 0 {
				cnt++
			}
		}
	}
	fmt.Println(cnt + x)
}


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

int main() {
  int ans=0;
  vector<int> N(5);
  for(int i=0;i<5;i++) cin >> N.at(i);

  for(int i=0;i<5;i++){
    if(N.at(i)==0){
      ans=i+1;
    }
  }

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

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n;
ll w[3010];
ll dp[3010][3010];
bool f[3010][3010];

int main() {
	while (cin >> n&&n) {
		rep(i, 301)rep(j, 301) {
			dp[i][j] = 0;
			f[i][j] = 0;
		}
		rep(i, n)cin >> w[i];

		for (int wid = 1; wid < n; wid++) {
			rep(i, n) {
				if (i + wid >= n)continue;
				if (wid == 1) {
					if (abs(w[i] - w[i + wid]) <= 1) {
						dp[i][i + wid] = 2;
						f[i][i + wid] = 1;
					}
				}
				else {
					if (wid % 2 == 1) {
						if (abs(w[i] - w[i + wid]) <= 1) {
							if (f[i + 1][i + wid - 1]) {
								dp[i][i + wid] = dp[i + 1][i + wid - 1] + 2;
								f[i][i + wid] = 1;
							}
						}
						dp[i][i + wid] = max(dp[i][i + wid], dp[i + 1][i + wid - 1]);
						for (int j = i + 1; j < i + wid; j++) {
							dp[i][i + wid] = max(dp[i][i + wid], (dp[i][j] + dp[j + 1][i + wid]));
							f[i][i + wid] |= (f[i][j] && f[j + 1][i + wid]);
						}
					}
					else {
						FOR(j, i, i + wid) {
							dp[i][i + wid] = max(dp[i][i + wid], dp[i][j] + dp[j + 1][i + wid]);
						}
					}
				}
			}
		}
		ll ans = 0;
		rep(i, n) {
			//ll sum = 0;
			FOR(j, i + 1, n) {
				//cout << i << " " << j << " " << dp[i][j] << endl;
				ans = max(ans, dp[i][j]);
				//if (dp[i][j])sum += max(ans, (ll)(j - i + 1));
			}
		}
		cout << ans << endl;
	}
}



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

using namespace std;
using ll = long long;

int main(int argc, char const* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d) ? "Yes" : "No") << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long n,a,b,ans;
  scanf("%d%ld%ld",&n,&a,&b);
  if(b<a) ans=0;
  else if(n==1){
    if(a!=b) ans=0;
    else ans=1;
  }
  else {
    ans=(n-2)*(b-a)+1;
  }
  printf("%ld",ans);
}

Measured memory_bytes: 128
import java.util.*;
import java.util.Map.Entry;
 
 
 class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
	 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        int[][] xy = new int[N][2];
        for(int i=0;i<N;i++) {
        	xy[i][0]=sc.nextInt();
        	xy[i][1]=sc.nextInt();
        }
        
        double sum=0;
        for(int i=0;i<N;i++) {
        	for(int j=0;j<N;j++) {
        		if(i==j)continue;
//        		System.out.println(Math.pow(xy[i][0]-xy[j][0], 2)+Math.pow(xy[i][1]-xy[j][1], 2));  
        		sum=sum+Math.pow(Math.pow(xy[i][0]-xy[j][0], 2)+Math.pow(xy[i][1]-xy[j][1], 2), 0.5);
        	}
        }
//        System.out.println(sum);        	
        double ans=(double)sum/N;
        
        System.out.println(ans);        	
                		
    }
}

Measured memory_bytes: 21972
package main

import "fmt"

var n, m int
var a []int

func main() {
	fmt.Scan(&n, &m)
	a = make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	s := 0
	for i := range a {
		s += a[i]
	}
	l := (s + 4*m - 1) / (4 * m)
	cnt := 0
	for i := range a {
		if a[i] >= l {
			cnt++
		}
	}
	if cnt >= m {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

using namespace std;

int judge(string ss, int a)
{
	int len = ss.length(), ans = 0;
	for (int i = a; i < len; i++)
	{

		if (ss[i] != 'A' && ss[i] != 'T' && ss[i] != 'C' && ss[i] != 'G')
			break;
		ans++;
	}
	//cout << ans << endl;
	return ans;
}

int main()
{
	string ss;
	cin >> ss;
	int len = ss.length(), max = 0;
	for (int i = 0; i < len; i++)
	{
		int l = judge(ss, i);
		if (l > max)
			max = l;
	}
	cout << max;
}

Measured memory_bytes: 256
/******************************************
 * Try to be a Rainbow in Someone's cloud.*
 *                                        *
 ******************************************/

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define DHOKHA ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
ll dp[100005];
int main(){
   DHOKHA;
   ll n;
   cin>>n;
   ll a[n];
   ll i;
   for(i=0;i<n;i++){
   	cin>>a[i];
   }
   dp[0]=0;
   dp[1]=abs(a[1]-a[0]);
   for(i=2;i<n;i++){
   	dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i-2]-a[i]));
   }
   cout<<dp[n-1];
   
}



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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, K;
  cin >> N >> K;
  vint a(N);
  rep(i, N) cin >> a[i];
  vint asum(N+1, 0);
  rep(i, N) asum[i+1] = asum[i]+a[i];
  vint psum(N+1, 0);
  rep(i, N) psum[i+1] = psum[i]+max(0ll, a[i]);
  int ans = 0;
  rep(i, N-K+1) {
    int j = i+K;
    int sum = max(0ll, asum[j]-asum[i]);
    sum += psum[i];
    sum += psum[N]-psum[j];
    chmax(ans, sum);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
# -*- coding: utf-8 -*-


class FactMod():
    '''
    modの値が素数の時のfactと組み合わせを求める
    フェルマーの小定理を用いているため、modが素数以外の時は使えない
    '''

    def __init__(self, n, mod):
        '''
        コンストラクタ
        f:nまでの i!の値を　配列に入れる
        inv: (i!)^-1　の値を配列に入れる
        '''
        self.mod = mod
        self.f = [1]*(n+1)
        for i in range(1, n+1):
            self.f[i] = self.f[i-1]*i % mod

        self.inv = [pow(self.f[-1], mod-2, mod)]
        for i in range(1, n+1)[::-1]:
            self.inv.append(self.inv[-1]*i % mod)
        self.inv.reverse()

    def fact(self, n):
        '''
        n!の値を返す
        '''
        return self.f[n]

    def comb(self, n, r):
        '''
        nCrの値を返す
        '''
        if r < 0:
            return 0
        if n < r:
            return 0
        ret = self.f[n] * self.inv[n-r]*self.inv[r]
        ret %= self.mod
        return ret

    def perm(self, n, r):
        """
        nPrの値を返す
        """
        ret = self.f[n] * self.inv[n-r]
        ret %= self.mod
        return ret


N, K = map(int, input().split())
MOD = 10**9+7

F = FactMod(N+1, MOD)
for i in range(1, K+1):
    b = F.comb(K-1, i-1)
    r = F.comb(N-K+1, i)
    print(b*r % MOD)


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

void add(string &s){
	int k = s.size() - 1;
	int n = (s[k-1] - '0') + (s[k] - '0');
	s.erase(s.size()-1);
	s.erase(s.size()-1);
	if( n >= 10 ){
		n -= 10;
		s.push_back('1');
		s.push_back(n + '0');
	}else{
		s.push_back(n + '0');
	}
}

string solve(string s){
	while( true ){
		if( s.size() < 2 ) return "Audrey wins.";
		add(s);
		if( s.size() < 2 ) return "Fabre wins.";
		add(s);
	}
	return "";
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		cout << solve(s) << endl;
	}
}

Measured memory_bytes: 1208
#include<stdio.h>
int main(void)
{
	int n,i;
	long long h,a;
    a=1000000000+7;
	scanf("%d",&n);
	h=1;
	for(i=1;i<=n;i++){ 
		h=h*i;
		h=h%a;
	}
	printf("%d\n",h);
     return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ri rd<int>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; --i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++i)
typedef long long LL;
const int maxN = 2e5 + 7;
const LL INF = (1LL << 61) + 3;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return f ? x : -x;
}

int n;
LL a[maxN];

LL Max(vector<LL> &v) {
	LL res = 0;
	for (LL x : v) res = max(res, x);
	return res;
}

LL Min(vector<LL> &v) {
	LL res = INF;
	for (LL x : v) res = min(res, x);
	return res;
}

LL sum(int l, int r) {
	return a[r] - a[l-1];
}

void split(int l, int r, vector<LL> &lis) {
	int L = l, R = r-1, mid;
	while (L < R) {
		mid = (L + R) / 2;
		if (sum(l, mid) < sum(mid+1, r)) L = mid + 1;
		else R = mid;
	}
	lis.push_back(sum(l, L));
	lis.push_back(sum(L+1, r));
}

void _split(int l, int r, vector<LL> &lis) {
	int L = l, R = r-1, mid;
	while (L < R) {
		mid = (L + R) / 2 + 1;
		if (sum(l, mid) > sum(mid+1, r)) R = mid - 1;
		else L = mid;
	}
	lis.push_back(sum(l, L));
	lis.push_back(sum(L+1, r));
}

int main() {

	n = ri();
	rep (i, 1, n) a[i] = ri() + a[i-1];

	LL res = INF;
	rep (i, 2, n-2) {
		vector<LL> lis;

		lis.clear();
		split(1, i, lis);
		split(i+1, n, lis);
		res = min(res, Max(lis) - Min(lis));

		lis.clear();
		split(1, i, lis);
		_split(i+1, n, lis);
		res = min(res, Max(lis) - Min(lis));

		lis.clear();
		_split(1, i, lis);
		split(i+1, n, lis);
		res = min(res, Max(lis) - Min(lis));

		lis.clear();
		_split(1, i, lis);
		_split(i+1, n, lis);
		res = min(res, Max(lis) - Min(lis));
	}
	printf("%lld\n", res);

	return 0;
}


Measured memory_bytes: 1792
n,m=map(int,input().split())
graph=[[] for _ in range(n)]

for _ in range(m):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

sign=[-1]*n
sign[0]=0
work=[]
work_next=graph[0]
for x in work_next:
    sign[x]=0


while work_next:
    work=work_next[:]
    work_next=[]
    for x in work:
        for y in graph[x]:
            if sign[y]>=0 : continue
            if y in work_next : continue
            sign[y]=x
            work_next.append(y)

if -1 in sign : print("No");exit()
print("Yes")
for i in range(1,n):
    print(sign[i]+1)

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

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

    ll ans = 0;
    for (int b = 1; b <= n; b++)
    {
        ans += (n / b) * max(0, b - 1 - k + 1);
        ans += max(0, (n % b) - k + 1);
    }
    if (k == 0)
        ans -= n;
    cout << ans << endl;
}

Measured memory_bytes: 256
//
// ~oisín~ C++ Template
//

#include                <bits/stdc++.h>
#define MX_N            5001
#define mp              make_pair
#define mod7            1000000007
#define modpi           314159
#define PI              3.141592653589793238
#define pb              push_back
#define FastIO          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define All(a)          a.begin(),a.end()
#define fi              first
#define se              second
#define ll              long long int
#define ull             unsigned long long int

int kx[8]  =            {+2, +2, -2, -2, +1, +1, -1, -1};
int ky[8]  =            {+1, -1, +1, -1, +2, -2, +2, -2};
int d9x[9] =            {+1, +1, +1, +0, +0, +0, -1, -1, -1};
int d9y[9] =            {+1, +0, -1, +1, +0, -1, +1, +0, -1};
int dx4[4] =            {+0, +0, +1, -1};
int dy4[4] =            {+1, -1, +0, +0};

ll gcd(ull a, ull b){
    return (a==0)?b:gcd(b%a,a);
}

ll lcm(ull a, ull b){
    return a*(b/gcd(a,b));
}

const long long INF = 1e18;

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    if(k % 2 == 1){
        cout << "No\n";
        return 0;
    }
    if(k > 4*n || k < 2*n){
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n";
}
    


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)     cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
ll solve(int W, int i, vector<vl > &dp, vl &w, vl &v ){
	int n = v.size();
	if(W==0 || i==n)return 0;
	if(w[i]>W)return solve(W,i+1,dp,w,v);
	if(dp[i][W]!=-1)return dp[i][W];
	ll a = solve(W-w[i],i+1,dp,w,v)+v[i];
	ll b = solve(W,i+1,dp,w,v);
	return dp[i][W] = max(a,b);
}
int main(){
	fast_io;
	int n,W;
	cin>>n>>W;
	vl w(n),v(n);
	for(int i=0;i<n;i++){
		cin>>w[i]>>v[i];
	}
	vector<vl > dp(n+7, vl(W+7,-1));
	cout<<solve(W,0,dp,w,v);
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

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

int main(){
    int n,c=0;
    cin >> n;
    int n2=n;
    while(n2!=0){
        c+=n2%10;
        n2/=10;
    }
    if(n%c==0){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

    char S[4];
    scanf("%s", S);

    if(S[0] == S[1]){
        printf("Bad");
    }else if(S[1] == S[2]){
        printf("Bad");
    }else if(S[2] == S[3]){
        printf("Bad");
    }else{
        printf("Good");
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int n,l;
  cin >> n >> l;
  vi azi(n);
  int sum1 = 0, sum2 = 0;
  rep(i,n){
    azi[i] = l + i;
    sum1 += azi[i];
  }
  int a = 1000, ans, sa ;
  rep(i,n){
    sum2=0;
    for(int j=0;j<n;j++){
      
      if(i==j)continue;
      sum2 += azi[j];
    }
    sa = abs(sum1 - sum2);
    if(a > sa) ans = sum2;
    a = min(sa,a);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))


def conb(n,r): 
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
a,b = inpl()
res = 0
if a > 1:
    res += conb(a,2)
if b > 1:
    res += conb(b,2)
print(res)



Measured memory_bytes: 5880
#include <bits/stdc++.h>
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  vector<int> R;
  vector<int> G;
  vector<int> B;
  for( int i = 0; i < N; i++ ){
    if( S.at(i) == 'R' ) R.push_back(i);
    else if( S.at(i) == 'G' ) G.push_back(i);
    else if( S.at(i) == 'B' ) B.push_back(i);
  }
  
  int ans = 0;
  for( int i = 0; i < N; i++ ){ //真ん中の文字を決め打ち
    for( int j = 0; j < i; j++ ){ //それより前の文字について探索
      if( S.at(i) == S.at(j) ) continue;
      if( S.at(i) != 'R' && S.at(j) != 'R' ){
        auto Iter = lower_bound(R.begin(), R.end(), i);
        int now = R.end()-Iter;
        ans += now;
        if( i+i-j < N && S.at(i+i-j) == 'R' ) ans--;
      }else if( S.at(i) != 'G' && S.at(j) != 'G' ){
        auto Iter = lower_bound(G.begin(), G.end(), i);
        int now = G.end() - Iter;
        ans += now;
        if( i+i-j < N && S.at(i+i-j) == 'G' ) ans--;
      }else if( S.at(i) != 'B' && S.at(j) != 'B' ){
        auto Iter = lower_bound(B.begin(), B.end(), i);
        int now = B.end() - Iter;
        ans += now;
        if( i+i-j < N && S.at(i+i-j) == 'B' ) ans--;
      }
    }
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 3688
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 12 00:18:59 2019

@author: Atsushi
"""

while True:
    n, x = map(int,input().split())
    if n == x == 0:
        break
    count = 0
    #1 ~ n まで
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i+j+k==x:
                    count+=1
    print(count)


Measured memory_bytes: 5612
# 上皿天秤は、左の皿に乗っているおもりの重さの合計を L とし、
# 右の皿に乗っているおもりの重さの合計を R としたとき、
# L > R なら左に傾き、 L = R なら釣り合い、
# L < R なら右に傾きます。
#
# 高橋君は、上皿天秤の左の皿に重さ A のおもりと重さ B のおもりを、
# 右の皿に重さ C のおもりと重さ D のおもりを置きました。
#
# 上皿天秤が左に傾くなら Left を、
# 釣り合うなら Balanced を、
# 右に傾くなら Right を出力してください。

# 制約
# 1 ≦ A, B, C, D ≦ 10
# 入力はすべて整数である

# 標準入力から A, B, C ,D の値を取得する
a, b, c, d = map(int, input().split())

# 上皿天秤の状態を判定し、結果を出力する
result = "ret"

if (a + b) > (c + d):
    result = "Left"
elif (a + b) < (c + d):
    result = "Right"
else:
    result = "Balanced"

print(result)


Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll func(ll x){
	while(x%10!=0){
		x--;
	}
	return x;
}
int main(){ 
ll n;
	cin>>n;
if(n%2==1) cout<<0;
  else{
	n=func(n);
	n/=2;
	ll ans=0;
	while(n>0){
               	ans=ans+n/5;
	      	n/=5;
	}
	cout<<ans;	}

}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	list := getStdinIntArr()
	N := list[0]
	M := list[1]
	X := list[2]
	C := make([]int, N)
	A := make([][]int, N)
	for i := 0; i < N; i++ {
		A[i] = make([]int, M)
	}

	for i := 0; i < N; i++ {
		list2 := getStdinIntArr()
		C[i] = list2[0]
		for j := 0; j < M; j++ {
			A[i][j] = list2[j+1]
		}
	}

	maxBit := (1 << N) - 1
	moneyMin := math.MaxInt32
	for bit := 1; bit <= maxBit; bit++ {
		money := 0
		AC := make([]int, M)
		for i := 0; i < N; i++ {
			mask := 0
			if i == 0 {
				mask = 1
			} else {
				mask = 1 << i
			}
			if (bit & mask) != 0 {
				money += C[i]
				for n := 0; n < M; n++ {
					AC[n] += A[i][n]
				}
			}
		}
		flag := true
		for i := 0; i < M; i++ {
			if AC[i] < X {
				flag = false
				break
			}
		}
		if flag && money < moneyMin {
			moneyMin = money
		}
	}

	if moneyMin == math.MaxInt32 {
		fmt.Printf("%d\n", -1)
	} else {
		fmt.Printf("%d\n", moneyMin)
	}
}

func getStdin() string {
	sc.Scan()
	return sc.Text()
}
func getStdinInt() int {
	sc.Scan()
	rtn, _ := strconv.Atoi(sc.Text())
	return rtn
}
func getStdinInt64() int64 {
	sc.Scan()
	rtn, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return rtn
}
func getStdinIntArr() []int {
	sc.Scan()
	str := sc.Text()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	sc.Scan()
	str := sc.Text()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}


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

int main(){
    string s;
    cin>>s;
    string ans="";
    int n=s.size();
    

    for(int i=0;i<n;i++){
        if(s[i]!='B'){
            ans+=s[i];
        }
        else if(ans.size()!=0) ans.erase(ans.size()-1,ans.size());
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#define ll long long
#define il inline
#define rgi register int

using namespace std;

const int oo = 0x3f3f3f3f;
const int N = 100000 + 10;

int n, m, ans;
int a[N];

struct GIVE
{
	int a, b;
} p[N];

struct Seg_Tree
{
	int lc, rc;
	ll add, val;
	Seg_Tree()
	{
		add = 0;
	}
} t[N << 2];

il int read()
{
	rgi x = 0, f = 0, ch;
	while(!isdigit(ch = getchar())) f |= ch == '-';
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

void Update(int p)
{
	t[p].val = max(t[p << 1].val, t[p << 1 | 1].val);
}

void Build(int p, int l, int r)
{
	t[p].lc = l, t[p].rc = r;
	if(l == r)
	{
		t[p].val = a[l];
		return ;
	}
	int mid = l + r >> 1;
	Build(p << 1, l, mid);
	Build(p << 1 | 1, mid + 1, r);
	Update(p);
}

void Spread(int p)
{
	if(t[p].add != 0)
	{
		t[p << 1].add += t[p].add;
		t[p << 1 | 1].add += t[p].add;
		t[p << 1].val += t[p].add * (t[p << 1].rc - t[p << 1].lc + 1);
		t[p << 1 | 1].val += t[p].add * (t[p << 1 | 1].rc - t[p << 1 | 1].lc + 1);
		t[p].add = 0;
	}
}

void Add(int p, int l, int r, int val)
{
	if(l <= t[p].lc && t[p].rc <= r)
	{
		t[p].add += val;
		t[p].val += val * (t[p].rc - t[p].lc + 1);
		return;
	}
	Spread(p);
	int mid = t[p].lc + t[p].rc >> 1;
	if(l <= mid)
		Add(p << 1, l, r, val);
	if(mid < r)
		Add(p << 1 | 1, l, r, val);
	Update(p);
}

int Query(int p, int l, int r)
{
	if(l <= t[p].lc && t[p].rc <= r)
		return t[p].val;
	Spread(p);
	int mid = t[p].lc + t[p].rc >> 1;
	int res = -oo;
	if(l <= mid)
		res = max(res, Query(p << 1, l, r));
	if(mid < r)
		res = max(res, Query(p << 1 | 1, l, r));
	return res;
}

bool cmp(struct GIVE A, struct GIVE B)
{
	if(A.b == B.b)
		return A.a < B.a;
	return A.b > B.b;
}

int main()
{
	n = read(), m = read();
	for(rgi i = 1; i <= n; ++i)
	{
		p[i].a = read();
		p[i].b = read();
	}
	sort(p + 1, p + n + 1, cmp);
	for(rgi i = 1; i <= n; ++i)
		a[i] = i;
	Build(1, 1, n);
	for(rgi i = 1; i <= n; ++i)
	{
		if(m - p[i].a + 1 < 1)
			continue;
		int maxn = Query(1, 1, m - p[i].a + 1);
		if(maxn <= 0)
			continue;
		ans += p[i].b;
		Add(1, maxn, maxn, -oo);
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 10752