akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fi firs
#define se second
#define pairs pair<int,int>
#define uppair pair<int,pairs>
#define downpair pair<pairs,int>
#define add push_back
#define upfor(i,x,y) for(int i=x; i<=y; i++)
#define downfor(i,x,y) for(int i=x; i>=y; i--)
#define sz(s) (int)s.size()
#define maxn 500010
using namespace std;
string s;
int n;
vector<int> a[maxn];
int ize[maxn];
int val[maxn], ipt[maxn], opt[maxn];
bool visit[maxn];
vector<int> p;

void DFS(int u)
{
    visit[u] = true;
    int t = 0;
    if(sz(a[u])!=0)
    {
        upfor(i,0,sz(a[u])-1)
        {
            int v = a[u][i];
            if(!visit[v]) DFS(v);
            ize[u]--;
            t = max(t,val[v]);
        }
        val[u] = t + 1;
    }
}

void solve()
{
    cin>>s;
    n = s.size();
    s = " " + s;
    upfor(i,1,n)
    {
        if(s[i] == '<')
        {
            ipt[i]++;
            opt[i+1]++;
            a[i+1].add(i);
        }
        if(s[i] == '>')
        {
            ipt[i+1]++;
            opt[i]++;
            a[i].add(i+1);
        }
    }
    upfor(i,1,n+1) ize[i] = a[i].size();
    upfor(i,1,n+1) if(ipt[i] == 0) p.add(i);
    int x;
    upfor(i,0,p.size()-1)
    {
        x = p[i];
        if(!visit[x]) DFS(x);
    }
    long long res = 0;
    upfor(i,1,n+1) res += val[i];
    cout<<res;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    freopen("test.inp","r",stdin);
//    freopen("test.out","w",stdout);
    solve();
    return 0;
}


Measured memory_bytes: 75440
#include<bits/stdc++.h>
 
 
using namespace std;
int main()
{
 
   int a, b;
    cin >> a >> b;
    if ((a+b)%2==0) {
        cout << (a+b)/2 << endl;
    }
    else {
        cout << "IMPOSSIBLE" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
Q = int(input())

ls = [list(map(int,input().split())) for i in range(Q)]

n_max = 10**5

prime = []
data = [i for i in range(2,n_max+1)]
limit = n_max**(1/2)

while True:
    p = data[0]
    if limit<=p:
        break
    prime.append(p)
    data = [i for i in data if i%p!=0]

prime = prime +data

ans_ls = [0]*(1+n_max)
for i in prime:
    if (i + 1) // 2 in prime:
        ans_ls[i] = 1

ans_cs = [0]*(1+n_max)
for i in range(n_max):
    ans_cs[i+1] = ans_cs[i]+ans_ls[i+1]
    
for l,r in ls:
    print(ans_cs[r]-ans_cs[l-1])




Measured memory_bytes: 100312
//file_name:ABC49_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int h,w;
    cin >> h >> w;


    rep(i,h){
        string s;
        cin >> s;
        cout << s << endl << s << endl;
    }
    return 0;
}



Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    h = list(map(int, input().rstrip('\n').split()))
    l = 0
    cnt = 0
    for i in range(n):
        if l < h[i]:
            cnt += h[i] - l
        l = h[i]
    print(cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
long long ara[101],sum[101];

int main()
{
   int a,b,c,d,i,j,ans=999999,k;
   string s,s1;
   cin>>s>>s1;
  int mid=s.size()-s1.size();
   for(i=0;i<=mid;i++)
   {
       c=0;
       for(j=i,k=0;k<s1.size();j++,k++)
       {
           if(s[j]!=s1[k])
            c++;
       }
       ans=min(ans,c);
   }
   cout<<ans<<"\n";




return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int dy8[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dx8[] = {0, 1, 0, -1, 1, 1, -1, -1};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    string S; cin >> S;

    REP(i,3) cout << S[i];

    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n=0,m=0,j=0,c=0,res=0,sum=0;
	cin>>n;
	int t[n];
	for( int i=0;i<n;i++){
		cin>>t[i];
		sum+=t[i];
	}
	cin>>m;
	int p[m],x[m];
	for(int j=0;j<m;j++){
		cin>>p[j]>>x[j];
	}
	for(int c=0;c<m;c++){
		res=(sum-(t[p[c]-1])+x[c]);
		cout<<res<<endl;
	}
	
}

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

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a, b; cin >> a >> b;
    cout << a * b / __gcd(a,b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <functional>
typedef long long int ll;
using namespace std;


template<typename T>
struct segtree{
  typedef function<T(T*, T*)> G; //merge
  typedef function<T(T*, T*)> H; //update
  ll M=1;
  G g;
  H h;
  T UNIT;
  vector<T> dat;

  segtree(ll N, T unit, G merge_func, H update_func):UNIT(unit){
    g = merge_func;
    h = update_func;
    while(M<N) M*=2;
    dat.resize(M*2-1, unit);
  }

  void update(T x, ll k, ll l=0, int r=-1){
    if(r==-1) r = M;
    k+=M-1;
    dat[k] = h(&dat[k], &x);
    while(k>0) {
      k = (k-1)/2;
      dat[k] = g(&dat[k*2+1], &dat[k*2+2]);
    }
  }

  T query(ll a, ll b=-1, ll k=0, ll l=0, ll r=-1){
    if(r==-1) r = M;
    if(b==-1) b = M;
    if(r<=a || b<=l) return UNIT;
    if(a<=l && r<=b) return dat[k];
    T A = query(a, b, k*2+1, l, (l+r)/2);
    T B = query(a, b, k*2+2, (l+r)/2, r);
    return g(&A, &B);
  }
};
ll mg(ll* a, ll* b){return *a|*b;}
ll upd(ll* old_elem, ll* new_elem){return *old_elem^*new_elem;}

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  string s;std::cin >> s;
  ll q;std::cin >> q;
  segtree<ll> seg(n+1, 0, mg, upd);
  for(int i=0;i<n;i++) seg.update(1<<(s[i]-'a'), i);
  for(int i=0;i<q;i++){
    ll a, b;std::cin >> a >> b;
    b--;
    if(a==1){
      char c;std::cin >> c;
      int pre = s[b] - 'a';
      int nw = c - 'a';
      seg.update((1<<pre), b);
      seg.update((1<<nw), b);
      s[b] = c;
    }else{
      ll c;std::cin >> c;
      ll q = seg.query(b, c);
      ll cnt = 0;
      for(int j=0;j<26;j++) if((q>>j)&1) cnt++;
      std::cout << cnt << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 9080
import java.util.Scanner;

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

		for(int i = str.length()-1; i >= 0; i--){
			System.out.print(str.charAt(i));
		}
		System.out.println();
	}
}

Measured memory_bytes: 12000
object Main extends App {
  val children = collection.mutable.Map.empty[String, Array[String]]
  val parent = collection.mutable.Map.empty[String, String]
  val n = io.StdIn.readInt()

  for {
    _ <- 0 until n
    l = io.StdIn.readLine()split(" ", 3)
  } l match {
    case Array(id, _) => children.put(id, Array.empty[String])
    case Array(id, _, nodes) =>
      val nodeSeq = nodes.split(" ")
      children.put(id, nodeSeq)
      nodeSeq foreach(parent.put(_, id))
  }

  for (i <- 0 until n) {
    val current = i.toString
    val p = parent.get(current) match {
      case None => "-1"
      case Some(x) => x
    }
    def depth(s: String): Int = parent.get(s) match {
      case None => 0
      case Some(x) => 1 + depth(x)
    }
    val d = depth(current)
    val c = children(current).mkString("[", ", ", "]")

    val t = if (p == "-1") "root" else if (c == "[]") "leaf" else "internal node"

    println(s"node $i: parent = $p, depth = $d, $t, $c")
  }
}

Measured memory_bytes: 289256
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
l = [0]*m
r = [0]*m

for i in range(m):
    l[i], r[i] = map(int, input().split())


left = -1
right = 10**9

for i in range(m):
    left = max(left, l[i])
    right = min(right, r[i])
    if left>right:
        print(0)
        exit()

print(right - left + 1)

Measured memory_bytes: 10868
local mce, msq = math.ceil, math.sqrt
local function getprimes(x)
  local primes = {}
  local allnums = {}
  for i = 1, x do allnums[i] = true end
  for i = 2, x do
    if allnums[i] then
      table.insert(primes, i)
      local lim = x // i
      for j = 2, lim do
        allnums[j * i] = false
      end
    end
  end
  return primes
end


local function getdivisorparts(x, primes)
  local prime_num = #primes
  local tmp = {}
  local lim = mce(msq(x))
  local primepos = 1
  local dv = primes[primepos]
  while primepos <= prime_num and dv <= lim do
    if x % dv == 0 then
      local t = {}
      t.p = dv
      t.cnt = 1
      x = x // dv
      while x % dv == 0 do
        x = x // dv
        t.cnt = t.cnt + 1
      end
      table.insert(tmp, t)
      lim = mce(msq(x))
    end
    if primepos == prime_num then break end
    primepos = primepos + 1
    dv = primes[primepos]
  end
  if x ~= 1 then
    local t = {}
    t.p, t.cnt = x, 1
    table.insert(tmp, t)
  end
  return tmp
end

local function getdivisorCore(divisorparts)
  local t = {}
  local pat = 1
  local len = #divisorparts
  local allpat = 1
  for i = 1, len do
    allpat = allpat * (1 + divisorparts[i].cnt)
  end
  for t_i_pat = 0, allpat - 1 do
    local div = allpat
    local i_pat = t_i_pat
    local ret = 1
    for i = 1, len do
      div = div // (divisorparts[i].cnt + 1)
      local mul = i_pat // div
      i_pat = i_pat % div
      for j = 1, mul do
        ret = ret * divisorparts[i].p
      end
    end
    table.insert(t, ret)
  end
  table.sort(t)
  return t
end

local primes = getprimes(mce(msq(1000000007)))

local n, k = io.read("*n", "*n")
local a = {}
local sum = 0
for i = 1, n do
  a[i] = io.read("*n")
  sum = sum + a[i]
end

local dvp = getdivisorparts(sum, primes)
local dvs = getdivisorCore(dvp)

for id = #dvs, 1, -1 do
  local dv = dvs[id]
  local plus, minus = {}, {}
  local z = 0
  local c = 0
  for i = 1, n do
    local v = a[i] % dv
    if v <= dv - v then
      table.insert(minus, v)
      z = z - v
    else
      table.insert(plus, dv - v)
      z = z + dv - v
      c = c + dv - v
    end
  end
  if 0 < z then
    table.sort(plus)
    for i = #plus, 1, -1 do
      local v = plus[i]
      z = z - dv
      c = c - v
      if z == 0 then break end
    end
  elseif z < 0 then
    table.sort(minus)
    for i = #minus, 1, -1 do
      local v = minus[i]
      z = z + dv
      c = c + (dv - v)
      if z == 0 then break end
    end
  end
  if c <= k then print(dv) break end
end


Measured memory_bytes: 3260
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repri(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define repr(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define reprs(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

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

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;
typedef vector<int> VI;
typedef vector<ll> VL;

void Main() {
	int n;
	string s;
	cin >> n;
	cin >> s;

	rep(i,s.size()) {
		s[i] = s[i] + n;
		if (s[i] > 'Z') s[i] -= 26;
	}

	cout << s << LF;

}

int main(){
	FAST;
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr);
  console.log(arr.reduce((s, e) => s += ' ' + e, ''));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  let left, right, largest;
  const maxHeapify = (i) => {
    left = 2 * i + 1;
    right = 2 * i + 2;
    // if (left < n && arr[left] > arr[i]) largest = left;
    // else largest = i;
    // if (right < n && arr[right] > arr[largest]) largest = right;
    largest = [2 * i + 1, 2 * i + 2].filter(idx => idx < n).reduce((max, idx) => max = arr[idx] > arr[max] ? idx : max, i);
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 123152
n = int(input())
renz = 0
for i in range(n):
    d1,d2 = map(int,input().split())
    if d1 == d2:
        renz += 1
        if renz == 3:
            break
    else:
        renz = 0
if renz == 3:
    print('Yes')
else:
    print('No')

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

using namespace std;

int main()
{
	string S, T;
	cin >> S >> T;

	const int L = S.size();
	int ans = 0;
	for (int i = 0; i < L; ++i) {
		if (S[i] != T[i]) {
			++ans;
		}
	}
	cout << ans << endl;
}


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

using namespace std;
bool g[202][202];
char s[202][202];

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, ans = -1;
	cin >> N;
	rep(i,N)rep(j,N){
		cin >> s[i][j];
		if(s[i][j]=='1')g[i][j]=1;
	}
	
	rep(i,N){
		int cnt = 0;
		vector<bool> v(N);
		vector<vector<int>> V(N);
		v[i] = 1;
		V[0].push_back(i);
		bool ok = 1;
		while(ok){
			ok = 0;
			for(auto x:V[cnt]){
				rep(a,N){
					if(v[a]==0&&s[x][a]=='1'){
						V[cnt+1].push_back(a);
						v[a]=1;
						ok = 1;
					}
				}
			}
			cnt++;
		}
		ok = 1;
		for(int j=0;j<cnt;j++){
			for(int a=0;a<V[j].size();a++){
				for(int b=0;b<V[j].size();b++){
					int x = V[j][a];
					int y = V[j][b];
					if(g[x][y]){
						ok = 0;
						break;
					}
				}
				if(!ok)break;
			}
			if(!ok)break;
		}
		if(ok)ans = max(ans,cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
// A

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

int main(){
  string s,t;
  cin>>s>>t;
  cout << t << s << endl;
  return 0;
}


Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Array.Unboxed
import Data.Function (on)

main :: IO ()
main = do
  n <- getl toInt
  solve n <$> replicateM (gamen n) (getl $ wrds toInt) >>= mapM_ print

solve :: Int -> [[Int]] -> [Int]
solve n = map fst . sortBy (compare `on` (fst . snd)) . g . zip [1..] . sortBy (flip compare `on` snd) . assocs . foldl f (listArray (1,n) (repeat 0))
  where
    f :: UArray Int Int -> [Int] -> UArray Int Int
    f ar [a,b,c,d]
      | c > d = accum (+) ar [(a,3)]
      | c < d = accum (+) ar [(b,3)]
      | otherwise = accum (+) ar [(a,1),(b,1)]
    g ((x1,(y1,z1)) : (x2,(y2,z2)) : rs)
      | z1 == z2 = (x1,(y1,z1)) : g ((x1,(y2,z2)) : rs)
      | otherwise = (x1,(y1,z1)) : g ((x2,(y2,z2)) : rs)
    g rs = rs
    
gamen :: Int -> Int
gamen n = n * (n-1) `div` 2

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 8304
(defun solve (n heights)
  (loop with decreasing = nil
        for i from 0 below (1- n)
        for j = (1+ i)
        do (cond
             ((< (aref heights j) (aref heights i))
              (if (or (< 1 (- (aref heights i) (aref heights j))) decreasing)
                (return nil)
                (setf decreasing t)))
             ((= (aref heights i) (aref heights j)))
             (t (setf decreasing nil)))
        finally (return t)))

#-swank
(let* ((n (read))
       (heights (make-array n :element-type 'fixnum)))
  (loop for i from 0 below n
        do (setf (aref heights i) (read)))
  (format t "~:[No~;Yes~]~%" (solve n heights)))


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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class BIT():
    def __init__(self, n):
        i = 1
        while 2**i <= n:
            i += 1
        self.H = i
        self.N = 2**i
        self.A = [0] * self.N

    def find(self, i):
        r = 0
        while i:
            r += self.A[i]
            i -= i & (i-1) ^ i
        return r

    def update(self, i, x):
        while i < self.N:
            self.A[i] += x
            i += i & (i-1) ^ i

    def query(self, a, b):
        return self.find(b-1) - self.find(a-1)

def main():
    n,m = LI()
    d = collections.defaultdict(list)
    for _ in range(n):
        l,r = LI()
        d[r-l+1].append((l,r))
    r = [n]
    bit = BIT(m+3)
    c = n
    for i in range(2,m+1):
        for a,b in d[i-1]:
            c -= 1
            bit.update(a,1)
            bit.update(b+1,-1)
        t = c
        for j in range(i,m+1,i):
            t += bit.find(j)
        r.append(t)

    return '\n'.join(map(str,r))


print(main())




Measured memory_bytes: 127704
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];

void push(int x){
  S[++top]=x; 
}

int pop(){
  top--;
  return S[top+1];
}

int main(){
  int a, b;
  top=0;
  char s[100];

  while(scanf("%s", s) != EOF){
    if(s[0] == '+')
      {
	a=pop();
	b=pop();
	push(a+b);
      }
    else if(s[0] == '-')
      {
	b=pop();
	a=pop();
	push(a-b);
      }
    else if(s[0] == '*')
      {
	a=pop();
	b=pop();
	push(a*b);
      }
    else
      {
	push(atoi(s));
      }
  }
  
  printf("%d\n", pop());
  
  return 0;
}



Measured memory_bytes: 2144
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int K = scan.nextInt();
        int S = scan.nextInt();
        int a;
        int b;
        int cnt = 0;
        for (a = 0; a <= K; a++) {
            int qw = K;
            if (S - a < qw) {
                qw = S-a;
                }for (b = 0; b <= qw; b++) {
                if (S - a - b <= K) cnt++;
                
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 22868
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int const mxn=4444;
int n,m;
int a[mxn],b[mxn],c[mxn],d[mxn],e[mxn],f[mxn];
bool vis[mxn][mxn],up[mxn][mxn],dw[mxn][mxn],le[mxn][mxn],ri[mxn][mxn]; //blockage

int const dx[]={-1,0,1,0};
int const dy[]={0,-1,0,1};
vi xx={-MOD,MOD}, yy={-MOD,MOD};

void bfs(int x, int y){
	queue<ii>q;
	q.emplace(x,y);
	while(!q.empty()){
		x = q.front().fi;
		y = q.front().se;
		q.pop();
		if(vis[x][y])continue;
		vis[x][y]=1;
		for(int i=0; i<4; i++){
			if(i==0&&le[x][y])continue;
			if(i==1&&dw[x][y])continue;
			if(i==2&&ri[x][y])continue;
			if(i==3&&up[x][y])continue;
			int X = x+dx[i];
			int Y = y+dy[i];
			if(X<0||X>=(int)xx.size()-1)continue;
			if(Y<0||Y>=(int)yy.size()-1)continue;
			q.emplace(X,Y);
		}
	}
	return;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	cin >> n >> m;
	for(int i=0; i<n; i++){
		cin >> a[i] >> b[i] >> c[i];
		xx.pb(a[i]);
		xx.pb(b[i]);
		yy.pb(c[i]);
	}
	for(int i=0; i<m; i++){
		cin >> d[i] >> e[i] >> f[i];
		xx.pb(d[i]);
		yy.pb(e[i]);
		yy.pb(f[i]);
	}
	sort(all(xx));
	xx.erase(unique(all(xx)),xx.end());
	sort(all(yy));
	yy.erase(unique(all(yy)),yy.end());
	//setting up blockage
	for(int i=0; i<n; i++){
		int x1 = lower_bound(all(xx),a[i])-xx.begin();
		int x2 = lower_bound(all(xx),b[i])-xx.begin();
		int y = lower_bound(all(yy),c[i])-yy.begin();
		// at y x1 --- x2
		for(int j=x1; j<x2; j++){
			up[j][y-1]=1;
			dw[j][y]=1;
		}
	}
	for(int i=0; i<m; i++){
		int x = lower_bound(all(xx),d[i])-xx.begin();
		int y1 = lower_bound(all(yy),e[i])-yy.begin();
		int y2 = lower_bound(all(yy),f[i])-yy.begin();
		/* at x
			y1
			|
			|
			|
			y2
		*/
		for(int j=y1; j<y2; j++){
			ri[x-1][j]=1;
			le[x][j]=1;
		}
	}
	int x = lower_bound(all(xx),0)-xx.begin()-1; 
	int y = lower_bound(all(yy),0)-yy.begin()-1; 
	bfs(x,y);
	if(vis[0][0]||vis[xx.size()-1][yy.size()-1]){
		cout << "INF" << endl;
		return 0;
	}
	ll ans = 0LL;
	for(int i=0; i<(int)xx.size()-1; i++)
		for(int j=0; j<(int)yy.size()-1; j++)
			if(vis[i][j])
				ans += ll(xx[i+1]-xx[i])*(yy[j+1]-yy[j]);
	cout << ans << endl;
}	


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

 
int main() {
    int n,x;
    cin>>n>>x;
    int sum=0,ming=1001;
    rep(i,n){
        int m;
        cin>>m;
        sum+=m;
        ming=min(ming,m);
    }
    cout<<(x-sum)/ming+n<<endl;
  
}

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

typedef long long ll;

int main()
{
  ll n;
  ll tmp;
  std::string s;
  std::vector<ll> a;
  std::cin >> n;
  for (ll i = 0; i < n; i++) {
    std::cin >> tmp;
    a.push_back(tmp);
  }

  for (ll i = n - 1; i > 0; i -= 2) {
    std::cout << a[i] << " ";
  }
  std::cout << a[0];

  ll i = 0;
  if (n % 2 == 0)
    i = 2;
  else
    i = 1;
  for (; i < n; i += 2)
    std::cout << " " << a[i];
  std::cout << std::endl;

  return 0;
}


Measured memory_bytes: 3824
#include<iostream>
#include<vector>
using namespace std;
int N; vector<pair<int, int>>P;
int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			if (((i % 2 == 1 && j % 6 == 4) || (i % 2 == 0 && j % 6 == 1) || i == 1 || i == N || j == N) && (i + j) % 2 == 1)P.push_back(make_pair(i, j));
		}
	}
	cout << P.size() << endl;
	for (int i = 0; i < P.size(); i++)cout << P[i].first - 1 << ' ' << P[i].second - 1 << endl;
	return 0;
}

Measured memory_bytes: 2928
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    int N, M;
    cin >> N >> M;

    ll price[1 << N], dp[1 << N];
    rep(i, 1 << N) {
        price[i] = INF;
        dp[i] = INF;
    }

    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        int bit = 0;
        rep(j, b) {
            int c;
            cin >> c;
            bit |= 1 << (c - 1);
        }
        price[bit] = min(price[bit], a);
    }

    dp[0] = 0;
    rep(i, 1 << N) {
        rep(j, 1 << N) {
            dp[i|j] = min(dp[i|j], dp[i] + price[j]);
        }
    }

    if (dp[(1 << N) - 1] == INF) {
        cout << -1 << endl;
    }
    else {
        cout << dp[(1 << N) - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    long long N, x, ans = 0; cin >> N >> x;
    vector<long long> a(N);
    cin >> a[0];
    rep (i, 1, N) {
        cin >> a[i];
        if (a[i-1] + a[i] > x) { // 制約条件を満たさない場合
            long long diff = abs(x - a[i-1] - a[i]);  // 何回「操作」を行う必要があるか
            if (0 > a[i] - diff) {  // a[i-1]からも差し引く必要がある場合
                a[i-1] -= (diff - a[i]);
                a[i] = 0;
            }
            else {
                a[i] -= diff;
            }
            ans += diff;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
import numpy as np
N,M,C=map(int,input().split())
B=np.array(list(map(int,input().split())))
ans=0
for _ in range(N):
  A=np.array(list(map(int,input().split())))
  if np.sum(A*B)+C>0:
    ans+=1
print(ans)

Measured memory_bytes: 14536
S[1<<21],Q[1<<21],q,b,s,n,M=1<<21,i;main(m){for(S[q=*Q=342391]=7;b=Q[b%M];m=28679<<s%4*3,n=(b>>12&4095|(b&4095)<<12)&m|b&~m,S[n%M]||(q=Q[S[n%M]=(s^4)+8,q%M]=n))s=S[b%M],s%4-3&&(m=7<<s%8*3,n=b/8&m|b*8&m*8|b&~(m*9),S[n%M]||(q=Q[S[n%M]=s+9,q%M]=n)),s%4&&(m=7<<~-s%8*3,n=b*8&m*8|b/8&m|b&~(m*9),S[n%M]||(q=Q[S[n%M]=s+7,q%M]=n));for(;~scanf("%d",&q);++i-8||(b=i=!printf("%d\n",S[b%M]/8)))b|=q<<(7-i)*3;}

Measured memory_bytes: 0
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  "sort"
)

type Bomb [][]int
func (B Bomb) Len() int { return len(B) }
func (B Bomb) Less(i, j int) bool { return B[i][0] < B[j][0] }
func (B Bomb) Swap(i, j int) { B[i], B[j] = B[j], B[i] }

func Solve() {
  var H, W, M, h, w int
  var ok bool
  NextInt(&H, &W, &M)
  X := make([][]int, H)
  for i := range X { X[i] = []int{0, i} }
  Y := make([][]int, W)
  for i := range Y { Y[i] = []int{0, i} }
  B := make(map[int]map[int]struct{})
  for i := 0; i < M; i++ {
    NextInt(&h, &w)
    h--; w--
    X[h][0]++; Y[w][0]++
    if _, ok = B[h]; !ok { B[h] = make(map[int]struct{}) }
    B[h][w] = struct{}{}
  }
  sort.Sort(sort.Reverse(Bomb(X)))
  sort.Sort(sort.Reverse(Bomb(Y)))
  able, disable := 0, H + M
  L:
    for 1 < disable - able {
      med := (disable + able) / 2
      for _, x := range X {
        for _, y := range Y {
          if x[0] + y[0] > med { able = med; continue L }
          if x[0] + y[0] < med { break }
          if _, ok = B[x[1]]; !ok { able = med; continue L }
          if _, ok = B[x[1]][y[1]]; !ok { able = med; continue L }
        }
      }
      disable = med
    }
  Write(able)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntSlice(A *[]int) {
  L := strings.Split(NextLine(), " ")
  if len(L) == 1 && L[0] == "" {
    (*A) = make([]int, 0)
    return
  }
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatSlice(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  if len(L) == 1 && L[0] == "" {
    (*A) = make([]float64, 0)
    return
  }
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(S ...interface{}) {
  fmt.Fprintln(writer, S...)
}
func WriteIntSlice(A []int) {
  B := make([]interface{}, len(A))
  for i, a := range A { B[i] = a }
  fmt.Fprintln(writer, B...)
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

Measured memory_bytes: 102364
N,K = map(int, input().split())
R,S,P = map(int, input().split())
T = input()

ans = 0

a = -(-N//K)
r = N%K
T2 = T + 'x'*(K - r)

li = []
for i in range(K):
    st = ''
    for j in range(a):
        c = T2[j*K + i]
        if st == '':
            st += c
        elif st[0] == c:
            st += c
        else:
            li.append(st)
            if st[0] == 'r':
                ans += -(-len(st)//2)*P
            elif st[0] == 's':
                ans += -(-len(st)//2)*R
            elif st[0] == 'p':
                ans += -(-len(st)//2)*S
            st = c
        if j == a-1:
            li.append(st)
            if st[0] == 'r':
                ans += -(-len(st)//2)*P
            elif st[0] == 's':
                ans += -(-len(st)//2)*R
            elif st[0] == 'p':
                ans += -(-len(st)//2)*S

print(ans)

Measured memory_bytes: 5272
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
ll mod=1000000007;
const ll N=100005;
int main()
{
fast;
    ll n;
    cin>>n;
    if(n>=30)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100000;

vector<int> G[MAX_N];
vector<pair<int, int> > bridge;
int ord[MAX_N];	//訪問時間
int low[MAX_N]; //low[u]はuから高々1個の後退辺を通ってたどりつけるノードのordの最小値
bool visit[MAX_N]; //訪問したかどうかのフラグ

void dfs(int v,int p,int &k) //&にすることでkを保持できる pはvの親
{
	visit[v] = true;
	ord[v] = k++;
	low[v] = ord[v];
	for(int i=0;i<G[v].size();i++){
		if(!visit[G[v][i]]){
			dfs(G[v][i],v,k);
			low[v] = min(low[v],low[G[v][i]]);	//子のノードのlowと比較する
			if(ord[v] < low[G[v][i]]){
				bridge.push_back(make_pair(min(v,G[v][i]), max(v,G[v][i])));
			}
		}else if(G[v][i] != p){
			low[v] = min(low[v],ord[G[v][i]]); //後退辺でたどった先の訪問時間と比較する
		}
	}
}

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		int x,y;
		scanf("%d %d",&x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	int k = 0;
	fill(visit,visit+n,false);
	for(int i=0;i<n;i++){
		if(!visit[i]) dfs(i,-1,k);
	}
    cout << (int)bridge.size() << endl;
}


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

int main(){
	int n;
	while(cin >> n && n){
		while(n--){
			int A[4],B[4];
			cin >> A[0] >> A[1] >> A[2] >> A[3];
			cin >> B[0] >> B[1] >> B[2] >> B[3];
			int ans[4] = {0};
			for(int i=0;i<4;i++){
				for(int j=0;j<4;j++){
					if(i == 0) ans[j] += A[i]*B[j];
					else if(j == 0) ans[i] += A[i]*B[j];
					else if(i == 1 && j == 2) ans[3] += A[i]*B[j];
					else if(i == 2 && j == 1) ans[3] += -(A[i]*B[j]);
					else if(i == 3 && j == 1) ans[2] += A[i]*B[j];
					else if(i == 1 && j == 3) ans[2] += -(A[i]*B[j]);
					else if(i == 2 && j == 3) ans[1] += A[i]*B[j];
					else if(i == 3 && j == 2) ans[1] += -(A[i]*B[j]);
					else ans[0] += -(A[i]*B[j]);
				}
			}
			bool flg = false;
			for(int i=0;i<4;i++){
				if(flg) cout << " ";
				else flg = true;
				cout << ans[i];
			}
			cout << endl;
		}
	}
}

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

typedef pair<int,int> P;
typedef pair<int,P> P1;

int h, w, A[1005][1005], ans[1005][1005];
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};

signed main(){
  
  memset(ans,-1,sizeof(ans));
    
  cin>>h>>w;
  
  queue<P1> Q;
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      
      char c;
      cin>>c;
      
      if( c == '#' ){
	A[i][j] = 1;
	Q.push(P1(0,P(i,j)));
	ans[i][j] = 0;
      }
      else A[i][j] = 0;
      
    }
  }
  
  while(!Q.empty()){
    
    P1 t = Q.front(); Q.pop();
    int cost = t.first;
    int y = t.second.first;
    int x = t.second.second;
    
    for(int i=0;i<4;i++){
      
      int ny = y + dy[i];
      int nx = x + dx[i];
      int ncost = cost + 1;
      
      if( ny < 0 || nx < 0 || h <= ny || w <= nx ) continue;
      
      if( ans[ny][nx] == -1 ){
	
	ans[ny][nx] = ncost;
	Q.push(P1(ncost,P(ny,nx)));
	
      }
      
    }
    
  }
  
  int maxcost = 0;
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++) maxcost = max( maxcost, ans[i][j] );
  }
  
  cout<<maxcost<<endl;
  
  return 0;
}


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

int main(){
    long long  n,k,q,a,ans[100000]={};
    cin>>n>>k>>q;
    for(int i=0;i<n;i++) ans[i]=k-q;
    for(int i=0;i<q;i++){
        cin>>a;
        a--;
        ans[a]++;
    }
    for(int i=0;i<n;i++){
        if(ans[i]>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 4412
#include <iostream>
#include <cmath>
#include <string>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main() {
  int H, W, dist[20][20] = {};
  char S[20][20];
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') continue;
      int d[20][20] = {};
      int visited[20][20] = {};
      queue<P> q;
      d[i][j] = 0;
      q.push(P(i, j));
      visited[i][j] = 1;
      while (!q.empty()) {
        P pos = q.front();
        int x = pos.first;
        int y = pos.second;
        if (x - 1 >= 0) {
          if (S[x-1][y] == '.' && visited[x-1][y] == 0) {
            d[x-1][y] = d[x][y] + 1;
            q.push(P(x-1, y));
            visited[x-1][y] = 1;
          }
        }
        if (x + 1 < H) {
          if (S[x+1][y] == '.' && visited[x+1][y] == 0) {
            d[x+1][y] = d[x][y] + 1;
            q.push(P(x+1, y));
            visited[x+1][y] = 1;
          }
        }
        if (y - 1 >= 0) {
          if (S[x][y-1] == '.' && visited[x][y-1] == 0) {
            d[x][y-1] = d[x][y] + 1;
            q.push(P(x, y-1));
            visited[x][y-1] = 1;
          }
        }
        if (y + 1 < W) {
          if (S[x][y+1] == '.' && visited[x][y+1] == 0) {
            d[x][y+1] = d[x][y] + 1;
            q.push(P(x, y+1));
            visited[x][y+1] = 1;
          }
        }
        q.pop();
      }
      for (int a = 0; a < H; a++) {
        for (int b = 0; b < W; b++) {
          dist[i][j] = max(dist[i][j], d[a][b]);
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(dist[i][j], ans);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 380
import sys
sys.setrecursionlimit(10000)  # 再帰関数のRecursionError対策

n, x = map(int, input().split())
As = [1]  # レベルiバーガーの厚さ（層の総数）（必ず奇数）
Ps = [1]  # レベルiバーガーのパティの総数

for i in range(n):
    As.append(As[i]*2 + 3)  # レベルが1上がると、総数は2倍+3になる
    Ps.append(Ps[i]*2 + 1)  # レベルが1上がると、パティの数は2倍+1になる

def f(n, x):
    """レベルnバーガーの下からx層食べたときの、食べたパティの総数"""
    if n == 0:
        return 0 if x <= 0 else 1

    median = (As[n]+1)//2

    if x < median:
        return f(n-1, x-1)
    elif x == median:
        return Ps[n-1] + 1
    elif x > median:
        return Ps[n-1] + 1 + f(n-1, x-median)

ans = f(n, x)

print(ans)

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

int main() {
  int n;
  cin >> n;
  vector<tuple<string, int, int>>a;
  for (int i = 1; i <= n; i++)
  {
    string s;
    int p;
    cin >> s >> p;
    a.emplace_back(s, -p, i);
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++)
  {
    cout << get<2>(a[i]) << endl;
  }
}

Measured memory_bytes: 256
from collections import defaultdict
    
class Combinatorics:
    def __init__(self, N, mod):
        '''
        Preprocess for calculating binomial coefficients nCr (0 <= r <= n, 0 <= n <= N)
        over the finite field Z/(mod)Z.
        Input:
            N (int): maximum n
            mod (int): a prime number. The order of the field Z/(mod)Z over which nCr is calculated.
        '''
        self.mod = mod
        self.fact = {i: None for i in range(N+1)}         # n!
        self.inverse = {i: None for i in range(1, N+1)}   # inverse of n in the field Z/(MOD)Z
        self.fact_inverse = {i: None for i in range(N+1)} # inverse of n! in the field Z/(MOD)Z
        
        # preprocess
        self.fact[0] = self.fact[1] = 1
        self.fact_inverse[0] = self.fact_inverse[1] = 1
        self.inverse[1] = 1
        for i in range(2, N+1):
            self.fact[i] = i * self.fact[i-1] % self.mod
            q, r = divmod(self.mod, i)
            self.inverse[i] = (- (q % self.mod) * self.inverse[r]) % self.mod
            self.fact_inverse[i] = self.inverse[i] * self.fact_inverse[i-1] % self.mod
    
    def perm(self, n, r):
        '''
        Calculate nPr = n! / (n-r)! % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return (self.fact[n] * self.fact_inverse[n-r]) % self.mod
    
    def binom(self, n, r):
        '''
        Calculate nCr = n! /(r! (n-r)!) % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return self.fact[n] * (self.fact_inverse[r] * self.fact_inverse[n-r] % self.mod) % self.mod
        
    def hom(self, n, r):
        '''
        Calculate nHr = {n+r-1}Cr % mod.
        Assign r objects to one of n classes.
        Arrangement of r circles and n-1 partitions:
            o o o | o o | | | o | | | o o | | o
        '''
        if n == 0 and r > 0:
            return 0
        if n >= 0 and r == 0:
            return 1
        return self.binom(n + r - 1, r)
    
n, k = map(int, input().split())
MOD = 10**9 + 7
com = Combinatorics(k, MOD)
ans = com.binom(k, n)
print(ans)


Measured memory_bytes: 6184
#include<cstdio>
#define mod 998244353
#define LL long long
#define N 300000
int n,a,b;
LL k,ans,C[N+5]={1};
LL M(LL x,LL y) { return x<y?x:y; }
LL powmod(LL x,int p)
{
	LL res=1;
	while(p)
	{
		if(p&1) res=res*x%mod;
		x=x*x%mod;
		p>>=1;
	}
	return res;
}
int main()
{
	scanf("%d%d%d%lld",&n,&a,&b,&k);
	for(int i=1;i<=n;i++) C[i]=1ll*(n-i+1)*powmod(i,mod-2)%mod*C[i-1]%mod;
	for(int i=0;i<=n&&1ll*i*a<=k;i++)
	{
		LL temp=1ll*i*a;
		if((k-temp)%b==0&&(k-temp)/b<=n)
		{
			LL x=(k-temp)/b;
			ans=(ans+C[x]*C[i])%mod;
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define dl double
#define PB push_back
#define MP make_pair
#define PPB pop_back
#define FI first
#define SE second
#define IN insert
#define ER erase
#define clean cout.flush()
#define PF push_front
#define PP pop
#define PH push
#define TP top
#define all(x) x.begin(),x.end()
#define REV reverse
#define IOS ios_base::sync_with_stdio(false);
#define inout freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
//Here I have defined all the things.....have you any problem?

const ll mod=1e9+7;
const ll lim=1e6+10;
ll ara[lim];
ll b[lim];
ll f[lim];
ll m[100010];

//fasting input and output
void faster()
{
    IOS; cin.tie(NULL); cout.tie(NULL);
}

void Chocolate()
{
    ll a,b;
    cin>>a>>b;
    bool chex=true;
    for(int i=0;i<=1000000;i++)
    {
        ll k=i*(0.08);
        ll k1=i*(0.1);
        if(k==a && k1==b)
        {
            chex=true;
            cout<<i;
            return;
        }
    }
    cout<<-1;
}
int main()
{
    faster();
    //inout;
    //if you hack my code you are a bullshit
    /*ll t; cin>>t; while(t--)*/Chocolate();
    return 0;
}
//Remember, "FAILURE IS THE PILLAR OF SUCCESS"


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

typedef long long ll;

ll n;
const int N = 1e6 + 5;
bool p[N];
bool v[N];

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

    for (int i = 2; i < N; ++i) {
        if (!p[i]) {
            for (int j = i + i; j < N; j += i) {
                p[j] = true;
            }
        }
    }
    for (int i = 2; i < N; ++i) {
        if (!p[i]) {
            if (!v[i]) {
                for (ll j = i; j < N; j *= i) {
                    v[j] = true;
                }
            }
        }
    }
    cin >> n;
    ll res = 0;

    for (int i = 2; i < N; ++i) {
        if (i > n) break;
        if (v[i]) {
            if (n % i == 0) {
                n /= i;
                ++res;
            }
        }
    }
    if (n >= N) ++res;
    cout << res << endl;

    return 0;
}



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

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	long n,m;
	cin>>n>>m;
	int a[m];
	long long s=0;
	for(int i=0;i<m;i++) {cin>>a[i];s+=a[i];}
	if(s<=n) cout<<n-s<<endl;
	else cout<<"-1\n";
	return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;  typedef pair<ll,ll> pii;
typedef vector<int> VI; typedef vector<ll> VL;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b,c,d,e,f;
	cin >>a >>b >>c >>d >>e >>f;
	a*=100; b*=100;
	
	VI vv1(f+10), vv2(f+10);
	rep(i,f/c+1) rep(j, f/d+1){
		int sm = i*c + j*d;
		if(sm <=f) vv1[sm] =1;
	}
	rep(i,f/a+1) rep(j, f/b+1){
		int sm = i*a + j*b;
		if(sm <=f ) vv2[sm] =1;
	}
	double mxx=0;
	int ans1=a, ans2 =0;
	rep(i, f+1) if(vv1[i]) rep(j, f+1) if(vv2[j]){
		if(i+j==0 || i +j > f) continue;
		if(  i * (e+100) <=  (i+j)  * e ){
			double w = 100.0 * i /(i+j);
			if(w > mxx){
				mxx = w; ans1 = i+j; ans2 =i;
				//dbg(i,j,w);
			}
		}
	}
	cout << ans1 <<" "<<ans2 <<"\n";
	
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<algorithm>

using namespace std;

typedef long long ll;

const int MX = 300005;
int ans[MX];

int main()
{
	int N, A, B;
	scanf("%d%d%d", &N, &A, &B);
	if (A + B > N+1 || (ll)A*B < N) return !printf("-1\n");

	int rm = N-A, cur = 1, sz = 0;
	for (int i = 1; i <= A; i++) {
		int t = min(B-1, rm)+1;
		for (int j = cur + t-1; j >= cur; j--) {
			ans[j] = ++sz; --rm;
		}
		rm++;
		cur += t;
	}
	for (int i = 1; i <= N; i++) printf("%d ", ans[i]);
	printf("\n");
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define all(v) (v).begin(),(v).end()
int main(){
	int n;
	cin>>n;
	vector<int> an(n);
	ll s=0;
	rep(i,n){
		cin>>an.at(i);
		s+=an.at(i);
	}
	vector<ll> xn(n,0);
	xn.at(0)=s;
	for(int i=1;i<n;i+=2){
		xn.at(0)-=2*an.at(i);
	}
	for(int i=1;i<n;i++){
		xn.at(i)=2*an.at(i-1)-xn.at(i-1);
	}
	rep(i,n){
		cout<<xn.at(i)<<endl;
	}
	return 0;
}

Measured memory_bytes: 2432