akhauriyash/Code-Regression huggingface dataset:
/*

    author : s@if

*/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define 		NIL 			-1
#define         SAIF            main
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			1e9
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> new_data_set;

//*find_by_order(k)  gives the kth element;
//order_of_key(item)   gives the index(number of element strictly less than item) of item;


inline int in() {int x; scanf("%d", &x); return x; }
bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};    // King's move
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hx[]={-2,-2,-1,+1,+2,+2,-1,+1};    // Knight's move
int hy[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)3e3+9;

vector<int>adj[MAXN];
int A[MAXN], dp[MAXN];

void dfs(int curr, int prev)
{
    dp[curr] = 0;
    bool flag = false;
    for(int i=0; i<adj[curr].size(); i++)
    {
        int v = adj[curr][i];
        if(v!=prev){
            dfs(v, curr);
            if(dp[v]==0 && A[v]<A[curr]) flag = true;
        }
    }

    if(flag) dp[curr] = 1;
}

int SAIF()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout); */

    ios_base::sync_with_stdio(false);
    cin.tie(0);  cout.tie(0);

    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>n; For(i,1,n) cin>>A[i];

    for(i=1; i<n; i++)
    {
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    for(i=1; i<=n; i++)
    {
        dfs(i,-1);
        if(dp[i]==1) cout<<i<<" ";
    }
    cout<<endl;

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 4012
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  vl a(n);
  vl cum(n + 1);
  ll l = 0;
  REP(i, n) {
    cin >> a[i];
    l += a[i];
  }
  cum[0] = 0;
  FOR(i, 1, n + 1) { cum[i] = cum[i - 1] + a[i - 1]; }

  ll ans = 20000000000;
  FOR(i, 1, n) {
    ll tmp = abs(cum[i] - (l - cum[i]));
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3328
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var N = sc.nextLong();
        var A = sc.nextLong();
        var B = sc.nextLong();
        var C = sc.nextLong();
        var D = sc.nextLong();
        var E = sc.nextLong();
        var arr = new long[] { A, B, C, D, E };


        WriteLine(4 + Math.Ceiling((decimal)N / (decimal)arr.Min()));
    }
}


class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 13268
// https://atcoder.jp/contests/abc175/tasks/abc175_c
#include <iostream>
#include <vector>
#include <deque>
#include <tuple>
#include <algorithm>
#include <iterator> // std::back_inserter
#include <climits>
#include <sstream>

using namespace std;

typedef long ll;

int main()
{
    ll n, d;
    cin >> n >> d;
    ll x[200001];
    ll y[200001];
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (x[i] * x[i] + y[i] * y[i] <= d * d)
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6748
#include <iostream>
#include <vector>
#define inf 1000000000

using namespace std;

struct edge{
	int to, cap, rev, back;
	edge(int a, int b, int c, int d){
		to = a, cap = b, rev = c, back = d;
	}
};


int N, M;
int S, T;
vector<edge> G[305];
bool used[305];

void add_edge(int s, int t, int cap, int back)
{
	G[s].push_back( edge(t, cap, G[t].size(), 0) );
	G[t].push_back( edge(s, 0, G[s].size()-1, back) );
}

int dfs(int v, int f)
{
	if(v == T) return f;
	used[v] = true;
	
	int ret;
	for(int i = 0; i < G[v].size(); i++){
		if(used[G[v][i].to] || G[v][i].cap == 0) continue;
		ret = dfs(G[v][i].to, min(f, G[v][i].cap));
		if(ret > 0){
			G[v][i].cap -= ret;
			G[G[v][i].to][G[v][i].rev].cap += ret;
			return ret;
		}
	}
	return 0;
}

int main(void)
{
	cin >> N >> M;
	
	int x, y;
	for(int i = 1; i <= M; i++){
		cin >> x >> y;
		add_edge(x, y, 1, 0);
		add_edge(y, x, 1, i);
	}
	cin >> S >> T;
	
	int flow = 0, ret;
	while(1){
		for(int i = 1; i <= N; i++) used[i] = false;
		ret = dfs(S, inf);
		if(ret == 0) break;
		flow += ret;
	}
	
	int cnt = 0;
	vector<int> ans;
	
	for(int i = 1; i <= N; i++){
		for(int j = 0; j < G[i].size(); j++){
			if(G[i][j].back && G[i][j].cap){
				cnt++;
				ans.push_back(G[i][j].back);
			}
		}
	}
	cout << flow << endl;
	cout << cnt << endl;
	for(int i = 0; i < cnt; i++){
		cout << ans[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int s;
  int s1, s2, s3;
  
  cin >> s;
  
  s1 = s / 100;
  s2 = ( s - s1 * 100 ) / 10;
  s3 = ( s - s1 * 100 - s2 * 10 ) / 1;
  
  cout << s1 + s2 + s3 << 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 vi = vector<int>;

const int MOD = 1000000007;

int main(){
    ll a,b,x;
    cin >> a >> b >> x;
    ll ans = b/x;
    
    ans -= a/x;
    if(a%x==0)ans++;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())

using namespace std;
typedef vector<long> VI;
typedef vector<VI> VVI;
// to:次の頂点,cap:辺の重み,rev:逆辺のindex
struct edge {long to,cap,rev;};
class Ford_fulkerson {
private:
	vector<vector<edge>> E;
	vector<bool> used;
	size_t V;
public:
	Ford_fulkerson() : V(0) { }

	Ford_fulkerson(size_t v) :
		E(v,vector<edge>(0)),used(v,false),V(v){ }

	size_t size() { return V;}

	void add_edge(long from,long to,long cap){
		E[from].push_back({to,cap,(long)E[to].size()});
		E[to].push_back({from,0,(long)E[from].size()-1});
	}

	long dfs(long node,long goal,long flow){
		if (node == goal) return flow;
		used[node] = true;
		REP(i,E[node].size()){
			edge* e = &E[node][i];
			if (!used[e->to] && e->cap != 0){
				long d = dfs(e->to,goal,min(flow,e->cap));
				if (d != 0) {
					e->cap -= d;
					E[e->to][e->rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

	long max_flow(long start,long goal){
		long ans = 0;
		while (1){
			REP(i,used.size()) used[i] = false;
			long f = dfs(start,goal,2147483647);
			if (f == 0) return ans;
			ans += f;
		}
	}
};

int main(void){
	long X,Y,E;
	long x,y;
	cin >> X >> Y >> E;
	Ford_fulkerson ff(X+Y+2);

	long start = X+Y;
	long goal = start+1;

	REP(i,E){
		cin >> x >> y;
		ff.add_edge(x,y+X,1);
	}

	REP(i,X) ff.add_edge(start,i,1);
	FOR(i,X,X+Y) ff.add_edge(i,goal,1);

	cout << ff.max_flow(start,goal) << endl;

	return 0;
}



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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)(n); i++)
#define reps(i,s,e) for(int i=s; i<(int)(e); i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Set = std::set<T>;
template<class T, class U>
using Map = std::map<T, U>;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = 1<<28;

int main() {
    int N;
    cin >> N;
    vint Ls(N);
    rep(i, N) {
        cin >> Ls[i];
    }
    int sum = 0;
    rep(i, N) {
        reps(j, i+1, N) {
            reps(k, j+1, N) {
                if (Ls[i] != Ls[j] && Ls[j] != Ls[k] && Ls[k] != Ls[i] && Ls[i] > Ls[k] - Ls[j] && Ls[j] > Ls[i] - Ls[k] && Ls[k] > Ls[j] - Ls[i]) {
                    sum++;
                }
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3628
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
	
#階乗#
lim = 50  #必要そうな階乗の限界を入力
fact = [1] * (lim+1)
for n in range(1, lim+1):
	fact[n] = n * fact[n-1] % mod

#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
	fact_inv[n-1] = n*fact_inv[n]%mod

def C(n, r):
	return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod


	
N, P = MAP()
A = LIST()

dp = [[0, 0] for _ in range(N+1)]
dp[0][0] = 1
dp[0][1] = 0  #dp[0]は一個も選ばないときのP=0,P=1になる組み合わせ

for i, a in enumerate(A):
	if a%2 == 0:
		dp[i+1][0] = dp[i][0] * 2
		dp[i+1][1] = dp[i][1] * 2
	else:
		dp[i+1][0] = dp[i][1] + dp[i][0]
		dp[i+1][1] = dp[i][0] + dp[i][1]

print(dp[N][P])

Measured memory_bytes: 10424
#include<iostream>
using namespace std;
#define  ll    long long int
#define  mod   1000000007   //10^9
#define  N     300005       //10^5
int main()
{
    int n,a,b,c,k;
    cin>>n;
    a=n%10;
    n/=10;
    b=n%10;
    n/=10;
    c=n%10;
    k=c;
    if(b>k)
    {
        k++;
        cout<<k<<k<<k<<endl;
    }
    else if(b<k)
    {
        cout<<k<<k<<k<<endl;
    }
    else
    {
        if(a<=k)
            cout<<k<<k<<k<<endl;
        else
        {
            k++;
            cout<<k<<k<<k<<endl;
        }
    }
    return 0;
}


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

ll mod = 1e9+7;


int main(){


    ll n, m; cin >> n >> m;
    if(abs(n-m) > 1) cout << 0 << endl;
    else{
        ll res = 1;
        for(ll i = 1; i <= n; i++)
            res = (res*i)%mod;
        for(ll i = 1; i <= m; i++)
            res = (res*i)%mod;
        if(n == m) res = (res*2)%mod;
        cout << res << endl;
    }
	return 0;
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long ll;
typedef pair<int, int> pint;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;


int main() {
    string s, t; cin >> s >> t;
    int n = s.size();
    rep(i, n) {
        string rotate = s.substr(i, n-i) + s.substr(0, i);
        if (rotate == t) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;


    return 0;
}


    


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

namespace ABC117_B
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			string[] input = Console.ReadLine().Split();
			int maxL = int.Parse(input[0]);
			int sum = maxL;
			for (int i = 1; i < n; i++)
			{
				int l = int.Parse(input[i]);
				if (l > maxL)
					maxL = l;
				
				sum += l;
			}
			
			sum -= maxL * 2;
			if(sum > 0) Console.WriteLine("Yes");
			else Console.WriteLine("No");
		}
	}
}


Measured memory_bytes: 13140
N = int(input())
S = input()

A = []
w = 0
for si in S:
    if si == 'W':
        w += 1
    A.append([w])

# E = []
e = 0
for i, si in enumerate(S[::-1]):
    if si == 'E':
        e += 1
    # E.append(e)
    A[-1 * i - 1].append(e)

# E = E[::-1]
# for i in range(N):
#     A[i][1] = E[i]

ans = N
for ai in A:
    ans = min(ans, ai[0] + ai[1] - 1)
print(ans)

Measured memory_bytes: 48628
H, W = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(H)]
ans = []
N = 0
for i in range(H):
    for j in range(W - 1):
        if (grid[i][j]) % 2  == 1:
            x = grid[i][j]
            ans.append([i + 1, j + 1, i + 1, j + 2])
            grid[i][j + 1] += 1
            grid[i][j] -= 1
            N += 1

    if i < H - 1 and (grid[i][W - 1]) % 2 == 1:
        y = grid[i][W - 1]
        ans.append([i + 1, W, i + 2, W])
        grid[i][W - 1] -= 1
        grid[i + 1][W - 1] += 1
        N += 1

print(N)
if N > 0:
    for proc in ans:
        y, x, Y, X = proc
        print(y, x, Y, X)
        



Measured memory_bytes: 31516
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
 
c1 = Counter(v[::2])
c2 = Counter(v[1::2])
m1 = c1.most_common()
m2 = c2.most_common()
t2 = n//2
t1 = n - t2
 
if len(m1) == len(m2) == 1:
    print(n//2 if m1[0][0] == m2[0][0] else 0)
elif len(m1) == 1:
    if m1[0][0] != m2[0][0]:
        print(t1 - m2[0][1])
    else:
        print(t1 - m2[1][1])
elif len(m2) == 1:
    if m1[0][0] != m2[0][0]:
        print(t2 - m1[0][1])
    else:
        print(t2 - m1[1][1])
else:
    if m1[0][0] != m2[0][0]:
        print(n - m1[0][1] - m2[0][1])
    else:
        ans = n - m1[1][1] - m2[1][1]
        if m1[0][0] != m2[1][0]:
            ans = min(ans, n - m1[0][1] - m2[1][1])
        if m1[1][0] != m2[0][0]:
            ans = min(ans, n - m1[1][1] - m2[0][1])
        print(ans)

Measured memory_bytes: 21184
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int x,y,z,k;
long long a[1000],b,c;
vector<long long> v1,v2;
int main(){
    cin>>x>>y>>z>>k;
    for(int i=0;i<x;i++)cin>>a[i];
    for(int i=0;i<y;i++){
        cin>>b;
        for(int j=0;j<x;j++)v1.push_back(b+a[j]);
    }sort(v1.begin(),v1.end(),greater<long long>());
    for(int i=0;i<z;i++){
        cin>>c;
        for(int j=0;j<min(k,(int)v1.size());j++)v2.push_back(c+v1[j]);
    }sort(v2.begin(),v2.end(),greater<long long>());
    for(int i=0;i<k;i++)cout<<v2[i]<<endl;
}

Measured memory_bytes: 43364
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC015A
{
    class Program
    {
        static void Main(string[] args)
        {
            int N, A, B;
            string[] vals = Console.ReadLine().Split(' ');
            N = int.Parse(vals[0]);
            A = int.Parse(vals[1]);
            B = int.Parse(vals[2]);

            if(A > B)
            {
                Console.WriteLine(0);
                return;
            }

            if (N == 1)
            {
                if (A == B)
                {
                    Console.WriteLine(1);
                    return;
                }
                else
                {
                    Console.WriteLine(0);
                    return;
                }
            }
            else if (N == 2)
            {
                Console.WriteLine(1);
                return;
            }
            else
            {
                long min = (long)A * (N - 2);
                long max = (long)B * (N - 2);
                Console.WriteLine(max - min + 1);
            }

        }
    }
}


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

int main()
{
  int n , answer ;
  cin >> n ;
  vector<int> d(n) ;
  for(int i=0; i<n; i++)
    cin >> d.at(i) ;
  
  sort(d.begin(),d.end()) ;
  
  for(int i=0; i<n-1; i++)
    if(d.at(i) < d.at(i+1))
      answer++ ;
  
  cout << answer+1 << endl ;
}

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

int main() {
  ll d,g;
  cin >> d >> g;
  
  vector<ll> p(d), c(d);
  
  for(ll i=0; i<d; i++){
    cin >> p[i] >> c[i];
  }
  
  ll ans = 1001;
  
  for(ll i=0; i < (1<<d); i++){
    ll count = 0, point = 0;
        
    for(ll m=0; m<d; m++){
      count += ((i>>m) % 2) * p[m];
      point += ((i>>m) % 2) * (100 * (m+1) * p[m] + c[m]);
    }
    
    if(point >= g){
      ans = min(ans, count);
      continue;
    }

    for(ll m=d-1; m >= 0; m--){
      if(!((i>>m) % 2) && (g-point-1)/100/(m+1) + 1 < p[m]){
        count += (g-point-1)/100/(m+1) + 1;
        point += ((g-point-1)/100/(m+1) + 1) * (m+1) * 100;
        ans = (point >= g) ? min(ans, count) : ans;
        break;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let h: usize = read();
    let w: usize = read();
    let mut map: Vec<Vec<char>> = vec![];

    for _ in 0..h {
        let row: Vec<char> = read::<String>().chars().collect();
        map.push(row);
    }
    loop {
        let comm_map = compile(&map);
        if comm_map.len() == map.len() && comm_map[0].len() == map[0].len() {
            break;
        }
        map = comm_map;
    }

    for i in 0..map.len() {
        let mut row = String::new();
        for w in 0..map[i].len() {
            row += &map[i][w].to_string();
        }
        println!("{}", row);
    }
}

fn compile(map: &Vec<Vec<char>>) -> Vec<Vec<char>> {
    // horizontal -> vertical
    let mut hidx: Vec<bool> = vec![true; map.len()];
    for h in 0..map.len() {
        if map[h].iter().all(|x| *x == '.') {
            hidx[h] = false;
        }
    }

    let mut widx: Vec<bool> = vec![true; map[0].len()];
    for w in 0..map[0].len() {
        let mut all_clear = true;
        for h in 0..map.len() {
            if map[h][w] == '#' {
                all_clear = false;
                break;
            }
        }
        if all_clear {
            widx[w] = false;
        }
    }

    let mut comm_map: Vec<Vec<char>> = vec![];

    for h in 0..map.len() {
        if !hidx[h] {
            continue;
        }

        let mut row = vec![];
        for w in 0..map[0].len() {
            if widx[w] {
                row.push(map[h][w]);
            }
        }
        comm_map.push(row);
    }
    comm_map
}


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

#define REP(i, n) for(int i=0;i<int(n);++i)
#define FOR(i, a, b) for(int i=int(a);i<int(b);++i)

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

    int N, M;
    while (cin >> N >> M, N | M) {
        vector<int> h(N), w(M);
        REP(i, N) cin >> h[i];
        REP(i, M) cin >> w[i];

        unordered_map<int, int> width_counts;
        REP(left, M) {
            int sum = 0;
            FOR(right, left, M) {
                sum += w[right];
                width_counts[sum] += 1;
            }
        }

        long long ans = 0;
        REP(top, N) {
            int sum = 0;
            FOR(bottom, top, N) {
                sum += h[bottom];
                ans += width_counts[sum];
            }
        }

        cout << ans << "\n";
    }
}

Measured memory_bytes: 18724
data = []
while True:
  a,b = map(int, input().split())
  if a == 0:
    break
  else:
    data.append([a,b])

for i in range(len(data)):
  for x in range(data[i][0]):
    char = ""
    if x % 2 == 0:
      c = "#"
    else:
      c = "."
    for y in range(data[i][1]):
      char = char + c
      if c == "#":
        c = "."
      else:
        c = "#"
    print(char)
  print("")


Measured memory_bytes: 5628
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        l:i64,
        r:i64,
    }
    let mut ans = std::i64::MAX;
    'outer: for i in l..r+1 {
        for j in i+1..r+1 {
            if (i * j)%2019 == 0 {ans =0;break 'outer; }
            ans = min(ans,(i*j)%2019);
        }
    }
    println!("{}",ans);
}


fn is_prime(x:i64) -> bool {
    if x == 2 {return true;}
    if x < 2 || x % 2 == 0 {return false;}
    let mut j = 3;
    while j <= (x as f64).sqrt() as i64 {
        if x % j == 0 {
            return false;
        }
        j += 2;
    }
    true
}


Measured memory_bytes: 4476
import collections as col

N,K = map(int,input().split())
A = list(map(int,input().split()))

L= len(set(A))
A = col.Counter(A)

Aval = A.values()
Aval = sorted(Aval)

ans = 0

if L <= K:
    print(0)
    
else:
    for i in range(L-K):
        ans += Aval[i]
    print(ans)

Measured memory_bytes: 37168
#include<bits/stdc++.h>
typedef unsigned long long int ull;
typedef long long int ll;
#define endl '\n'
#define mod 1000000007
#define v vector
#define For(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define pb push_back
#define mk make_pair
#define S second
#define F first
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    ll n;
    cin>>n;
    ll a[n],b[n],c[n];
    For(i,n)cin>>a[i]>>b[i]>>c[i];
    ll ans[n][3];
    For(i,n)
    {
        if(i==0)
        {
            ans[i][0]=a[i];
            ans[i][1]=b[i];
            ans[i][2]=c[i];
        }
        else
        {
            ans[i][0]=a[i]+max(ans[i-1][1],ans[i-1][2]);
            ans[i][1]=b[i]+max(ans[i-1][0],ans[i-1][2]);
            ans[i][2]=c[i]+max(ans[i-1][0],ans[i-1][1]);
        }
    }
    cout<<max(ans[n-1][0],max(ans[n-1][1],ans[n-1][2]));
    return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

llong N, K;
vector<vector<llong> > edges;
vector<llong> sibling, used;

llong solve(llong bbefore, llong before, llong now) {
	llong ret = K - used[bbefore] - used[before] - sibling[now];
	llong add = 0;
	for (auto edge: edges[now]) {
		if (used[edge]) continue;
		used[edge] = 1;
		sibling[edge] = add++;
		ret = (ret * solve(before, now, edge)) % mod;
	}

	return ret;
}

int main() {
	cin >> N >> K;
	edges.resize(N+1);
	sibling.resize(N+1, 0);
	used.resize(N+1, 0);
	for (int i = 0; i < N-1; ++i) {
		int from, to;
		cin >> to >> from;
		edges[to].push_back(from);
		edges[from].push_back(to);
	}

	used[1] = 1;
	cout << solve(0, 0, 1) << endl;

	return 0;
}

Measured memory_bytes: 13184
use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::cmp::*;
use std::collections::*;
use std::iter::Iterator;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
  input! {
  n: usize,
  mut l: [i64; n],
  }

  l.sort();

  let mut cnt = 0_u64;
  for i in 0..n {
    for j in i+1..n {
      if l[i] == l[j]{
        continue;
      }
      for k in j+1..n {
        if l[j] == l[k]{
          continue;
        }

        if l[k] < l[i] + l[j]
        {
          cnt += 1;
        }
      }
    }
  }

  println!("{}", cnt);
}


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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

int main() {
    int L;
    cin >> L;
    printf("%.9lf\n", (L / 3.) * (L / 3.) * (L / 3.));
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM

-- haskell can be this iterative!
sieve :: Int -> V.Vector Bool
sieve upto = runST $ do
    s <- VM.replicate (upto+1) True
    VM.write s 0 False
    VM.write s 1 False
    forM_ [2..(ceiling.sqrt.fromIntegral $ upto)] $ \i -> do
        isP <- VM.read s i
        when isP $ forM_ [i*i, i*i+i..upto] (\n -> VM.write s n False)
    V.unsafeFreeze s

primes :: Int -> [Int]
primes = V.toList . V.map fst . V.filter snd . V.imap (,) . sieve

findRange :: Ord a => [a] -> a -> (a,a)
findRange (x:p@(y:_)) a = if x < a && not (y < a)
                              then (x, head . dropWhile (<= a) $ p)
                              else findRange p a

main = do
    let
        ps = primes 50100
        f = findRange ps
    getContents >>=
        mapM_ ((\(p0,p1) -> putStrLn . unwords . map show $ [p0,p1])
                . f . read) . lines

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

int main()
{
    double H, U, D, F;
    while(cin >> H >> U >> D >> F){
        if(H == 0) break;
        int DAY = 1;
        double IH = 0, DC = U, HAC = DC, HAS = HAC - D;
        double f = (F / 100.0) * U;
        int flag = 1;
        while(HAC <= H && HAC > 0){
            DAY++;
            IH = HAS;
            DC -= f;
            HAC = IH + DC;

            if(HAC > H){
                break;
            }

            HAS = HAC - D;

            cout << HAC << "\t" << HAS << "\t" << DC << "\n";

            if(HAS < 0.0) {
                cout << "failure on day " << DAY << "\n";
                flag = 0;
                break;
            }
        }
        if(flag && HAC > 0) cout << "success on day " << DAY << "\n";
        else if(flag) cout << "failure on day " << DAY << "\n";
    }

    return 0;
}*/


#include <bits/stdc++.h>
#define LL long long
using namespace std;

LL A[200005];
int main()
{
    int N;
    cin >> N;
    LL sum1 = 0, sum2 = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        sum1 += A[i];
    }
    LL Min = INT_MAX;
    for(int i = N-1; i > 0; i--){
        sum1 -= A[i];
        sum2 += A[i];
        Min = min(Min, abs(sum1-sum2));
    }
    cout << Min << "\n";
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
struct node
{
	int a,b,c,d;
};
vector<node> v;
int a[600][600];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		scanf("%d",&a[i][j]);
 
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(a[i][j]&1)
			{
                if(j<m)
				{
                    a[i][j] --;
                    a[i][j+1] ++;
                    node z;
                    z.a=i;
                    z.b=j;
                    z.c=i;
                    z.d=j+1;
                    v.push_back(z);
				}
				else if(i<n)
				{
					a[i][j]--;
					a[i+1][j]++;
					node z;
					z.a=i;
                    z.b=j;
                    z.c=i+1;
                    z.d=j;
                    v.push_back(z);
				}
			}
		}
	}
	printf("%d\n",v.size());
	for(int i=0;i<v.size();i++)
	{
		printf("%d %d %d %d\n",v[i].a,v[i].b,v[i].c,v[i].d);
	}
	return 0;
}

Measured memory_bytes: 5360
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>
#include <list>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

class unionfind
{
public:
    vector<ll> parent;
    vector<ll> ranks;

    void init(ll n)
    {
        REP(i, n)
        {
            parent.push_back(i);
            ranks.push_back(0);
        }
    }

    ll find(ll x)
    {
        return parent[x] == x ? x : parent[x] = find(parent[x]);
    }

    void unite(ll x, ll y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (ranks[x] < ranks[y])
        {
            parent[x] = y;
        }
        else
        {
            parent[y] = x;
            if (ranks[x] == ranks[y])
                ranks[x]++;
        }
    }
    bool same(ll x, ll y)
    {
        return find(x) == find(y);
    }
};

int main(void)
{
    int n, m;
    int ans = 0;
    cin >> n >> m;
    vector<pair<int, int>> edge;
    REP(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edge.push_back(make_pair(a, b));
    }
    REP(i, m)
    {
        unionfind uf;
        uf.init(n);
        REP(j, m)
        {
            if (i == j)
                continue;
            uf.unite(edge[j].first, edge[j].second);
        }
        int tmp = uf.find(0);
        bool flag = true;
        REP(j, n)
        {
            if (tmp != uf.find(j))
            {

                flag = false;
                break;
            }
        }
        if (!flag)
            ans++;
    }
    cout << ans << endl;
}


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

int main()
{
	ll N, M, Q;
	string S, B;
	while (cin >> N >> M >> Q, N | M | Q) {
		vector<ll> able(M, (1ll << N) - 1);
		ll s = 0;
		for (ll i = 0; i < Q; i++) {
			cin >> S >> B;
			for (ll j = 0; j < N; j++) {
				if (S[j] == '1') {
					s ^= 1ll << j;
				}
			}
			for (ll j = 0; j < M; j++) {
				if (B[j] == '1') {
					able[j] &= s;
				}
				else {
					able[j] &= ~s;
				}
			}
		}
		for (ll i = 0; i < M; i++) {
			ll res = -1;
			for (ll j = 0; j < N; j++) {
				if (able[i] == (1ll << j)) {
					res = j;
					break;
				}
			}
			if (res == -1) {
				cout << '?';
			}
			else if (res < 10) {
				cout << res;
			}
			else {
				cout << (char)(res - 10 + 'A');
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3148
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const double PI = acos(-1.0);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    vector<ll> H(N+1);
    rep(i,N) cin >> H[i+1];

    if (K==N) {
        cout << 0 << ln;
        return 0;
    } 
    vector<vector<ll>> dp(N+1, vector<ll>(N-K+1,1e18));
    dp[0][0] = 0;
    rep(i,N) {
        rep(j,N-K) {
            rep(k,i+1) {
                chmin(dp[i+1][j+1],dp[k][j] + max(0LL,H[i+1]-H[k]));
            }
        }
    }
    ll ans = 1e18;
    rep(i,N+1) chmin(ans,dp[i][N-K]);
    cout << ans << ln;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> int_pair;
typedef pair<ll,ll> ll_pair;
#define pb push_back
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
const int N=100;
const int W=10000;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	unordered_map<ll,ll> um;
	ll n,m,w=0,ans=0;
	cin>>n>>m;
	um[w]++;
	FOR(i,0,n){
		ll k;
		cin>>k;
		w+=k;
		w%=m;
		ans += um[w];
		um[w]++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3724
import sys
import numpy as np

# import os
# path = os.getcwd()
# path = os.path.join(path,"input.txt")
# sys.stdin = open(path)

input = sys.stdin.readline
N,K = map(int,input().split())
h = [int(input()) for _ in range(N)]
h.sort()
ans = float("inf")
for i in range(N-K+1):
    ans = min(ans,h[i+K-1]-h[i])
print(ans)

Measured memory_bytes: 16740
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S, T; cin >> S >> T;
  cout << T << S << endl;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    if (unique(a.begin(), a.end()) == a.end()) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 4048
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>	tree_set;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll mod=1e9 + 7;

int main()
{
    fast();

    ll m,d;
    cin>>m>>d;

    ll ans = 0;
    for(ll i=1;i<=m;i++){
        for(ll j=2;j<=9;j++){
            for(ll k=2;k<=9;k++){
                if(j*k == i && (j*10 + k )<=d )
                    ans++;
            }
        }
    }

    cout<<ans;

}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	string s;
	ll k;
	cin >> s >> k;

	int n=s.length();
	for(int i=0; i<n; i++){
		if(s[i]=='a') continue;
		int c=26-(s[i]-'a');
		if(c<=k){
			s[i]='a';
			k-=c;
		}
	}
	if(k>0){
		s[n-1]+=k%26;
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#include <tuple>
#define ll long long
#define Inf 123372036854775806ll
using namespace std;



bool dp[2][22222];

bool Solve(const vector<int>& dists, int id, int curr, int dest) {
    
    
    for(int i=0;i<=20000;i++) {
        dp[0][i]=(i==curr);
    }
    
    for(int j=id;j<dists.size();j++) {
        for(int i=0;i<=20000;i++)
            dp[1][i]=false;
        for(int i=0;i<=20000;i++)
            if (dp[0][i]) {
                dp[1][i+dists[j]]=true;
                dp[1][i-dists[j]]=true;
            }
        for(int i=0;i<=20000;i++) {
            dp[0][i]=dp[1][i];
        }
        
    }
    
    return dp[0][dest];
    
    
}



int main() {
    
    string S;
    cin>>S;
    int destx,desty;
    cin>>destx>>desty;
    
    vector<int> x;
    vector<int> y;
    
    x.push_back(0);
    
    bool dir=false;
    
    for(int i=0;i<S.size();i++) {
        if (S[i]=='F') {
            
            
            
            if (!dir)
                x.back()++;
            else
                y.back()++;
        } else {
            dir=!dir;
            
            if (!dir)
                x.push_back(0);
            else
                y.push_back(0);
            
        }
        
    }
    

    bool canx = Solve(x, 1, 8000+x[0], 8000+destx);
    
    bool cany = Solve(y, 0, 8000, 8000+desty);
    
    if (canx && cany)
        printf("Yes\n");
    else
        printf("No\n");

    
    
    
    
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<string, string> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

void mul_mod(ll &a, ll b){
	a *= b;
	a %= MOD;
}

map<P, ll> mp;
vector<P> v;

int main(void){
	int n,i,j,m;
	string s,a,b,c,d;
	ll ans=0ll;
	cin >> n;
	cin >> s;
	m = (1<<n);
	i = n; j = 2*n-1;
	while(i < j){
		swap(s[i],s[j]);
		++i; --j;
	}
	for(i=0; i<m; ++i){
		for(j=0; j<n; ++j){
			if(i&(1<<j)){
				a.push_back(s[j]);
				c.push_back(s[j+n]);
			}else{
				b.push_back(s[j]);
				d.push_back(s[j+n]);
			}
		}
		++mp[P(a,b)];
		v.push_back(P(c,d));
		a.erase(a.begin(),a.end());
		b.erase(b.begin(),b.end());
		c.erase(c.begin(),c.end());
		d.erase(d.begin(),d.end());
	}
	for(i=(v.l_ength()-1); i>=0; --i){
		ans += mp[v[i]];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 90348
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] x = new int[n + 1];
		for (int i = 0; i < n; i++) {
			x[i] = Integer.parseInt(sa[i]);
		}
		int l = Integer.parseInt(br.readLine());
		int q = Integer.parseInt(br.readLine());
		int[] a = new int[q];
		int[] b = new int[q];
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			a[i] = Integer.parseInt(sa[0]) - 1;
			b[i] = Integer.parseInt(sa[1]) - 1;
		}
		br.close();
		x[n] = x[n - 1] + 1;

		int m = 18;
		int[][] dr = new int[m][n + 1];
		int r = 1;
		for (int j = 0; j <= n; j++) {
			while (r <= n && x[r] - x[j] <= l) {
				r++;
			}
			dr[0][j] = r - 1;
//			System.out.print(dr[0][j] + "\t");
		}
//		System.out.println();

		for (int i = 1; i < m; i++) {
			for (int j = 0; j <= n; j++) {
				dr[i][j] = dr[i - 1][dr[i - 1][j]];
//				System.out.print(dr[i][j] + "\t");
			}
//			System.out.println();
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			int now = Math.min(a[i], b[i]);
			int g = Math.max(a[i], b[i]);
			int ans = 0;
			for (int j = 0; j < m; j++) {
				if (dr[j][now] > g) {
					if (j == 0) {
						ans++;
						break;
					} else {
						ans += 1 << j - 1;
						now = dr[j - 1][now];
						j = -1;
					}
				} else if (dr[j][now] == g) {
					ans += 1 << j;
					break;
				}
			}
			pw.println(ans);
		}
		pw.flush();
	}
}


Measured memory_bytes: 64068
def solve():
    MOD = 10 ** 9 + 7
    H, W = map(int,input().split())
    a = [list(input()) for _ in range(H)]
    dp = [[0] * W for _ in range(H)]
    dp[0][0] = 1

    for h in range(H):
        for w in range(W):
            if w-1 >= 0 and a[h][w-1] == '.':
                dp[h][w] += dp[h][w-1] % MOD
            if h-1 >= 0 and a[h-1][w] == '.':
                dp[h][w] += dp[h-1][w] % MOD

    print(dp[-1][-1] % MOD)
if __name__ == '__main__':
    solve()

Measured memory_bytes: 87920
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+7;
long long n;
long long a[MAX];
long long b[MAX];
long long ans;

int main() {
	cin>>n;
	for(long long i=0; i<n+1; i++) cin>>a[i];
	for(long long i=0; i<n; i++) cin>>b[i];
	for(long long i=0; i<n; i++) {
		if(b[i]>a[i]) {
			ans+=a[i];
			b[i]-=a[i];
			if(a[i+1]>b[i]) {
				a[i+1]-=b[i];
				ans+=b[i];
			}
			else {
				ans+=a[i+1];
				a[i+1]=0;
			}
		}
		else ans+=b[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;

int main() {

	string n; cin >> n;

	int a = 0;

	for (auto& s : n){
		string b{s};
		if (b == "+"){
			a++;
		} else {
			a--;
		}
	}

	cout << a;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/reversed.hpp>
using namespace std;
constexpr char nl = '\n';
using ll = long long;
using boost::irange;
using boost::adaptors::reversed;
struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> auto operator>>(istream& in, C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, istream&>::type {
    for (auto& v : c) { in >> v; } return in; }
template<class C> auto operator<<(ostream& out, const C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, ostream&>::type {
    int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const char* s, const T& v) { cerr << s << "=" << v; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cerr << *s; } cerr << "=" << v << ","; trace_(++s, vs...); }
#define TRACE(...) (cerr << "\033[2m\033[33m", trace_(#__VA_ARGS__, __VA_ARGS__), cerr << "\033[0m\n")
#else
#define TRACE(...)
#endif

int main() {
    int k, t;
    cin >> k >> t;
    vector<int> as(t);
    cin >> as;
    int max_a = *max_element(as.begin(), as.end());
    int half = (k + 1) / 2;
    if (max_a <= half) {
        cout << 0 << nl;
    } else {
        cout << (max_a - (k - max_a) - 1) << nl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
	int n,s=0,q,a,b;
	cin >> n;
	int ar[100001]={0};
	for(int i=0;i<n;i++)
	{
		cin >> a;
		ar[a]++;
		s=s+a;
	}
	cin >> q;
	while(q--)
	{
		cin >> a >> b;
		int f=ar[a];
		s=s-(f*a);
		ar[a]=0;
		ar[b]=ar[b]+f;
		s=s+(f*b);
		cout << s <<"\n";
	}
		
	
	
}


Measured memory_bytes: 4384
N = int(input())
A = [0] * (10**4+1)
import math
import numpy
tmp=0
for i in range(1,int(math.sqrt(N))):
    for j in range(1,int(math.sqrt(N))):
        for k in range(1,int(math.sqrt(N))):
            tmp=(i+j+k)**2-(i*j+j*k+i*k)
            if tmp<=10**4:
                A[tmp]+=1
for p in A[1:N+1]:
    print(p)

Measured memory_bytes: 27344
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(f) (f).begin(),(f).end()
#define allr(f) (f).rbegin(),(f).rend()
const int mod = 1e9+7, A = 1e5+5;

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n, k;
	cin >> n >> k;
	ll a[n], ans = 0;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	for (int i = n-1; i >= 0; i--)
		!k? ans += a[i] : k--;
	cout << ans;
	return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atc_0024
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int result = 0;

            if (N % 2 == 0)
            {
                result = N / 2;
            }
            else
            {
                result = N / 2 + 1;
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 27516
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>

using namespace std;
using ll = long long int;

int main() {
	ll a, b, x;
	cin >> a >> b >> x;
	cout << (a <= x && a + b >= x ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int a[100]={0};
    int n;
    std::cin >> n;
    a[1]=0;
    for (int i = 2; i <= n; i++) {
        if(i%2==0){
            a[i]=a[i/2]+1;
        }else{
            a[i]=a[i/2];
        }
    }
    int max=1;
    for (int i = 1; i <= n; i++) {
        if(a[max]<a[i])max=i;
    }
    std::cout << max << std::endl;
}


Measured memory_bytes: 256