akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

vector <ll> spis;
ll X, Y;

ll nod(ll A, ll B)
{
 	if (A == 0) {X = 0, Y = 1; return 1;}
 	ll d = nod(B % A, A);
 	ll newX = -Y - (B / A) * X;
 	ll newY = -X;
 	X = newX, Y = newY;
 	return d;
}

int main()
{
 	//freopen("input.txt", "r", stdin);
 	//freopen("output.txt", "w", stdout);
 	ios_base::sync_with_stdio(0); cin.tie(0);
 	ll A;
 	cin >> A;
 	A *= 2;
 	ll answer = A;

 	ll uk = 2;
 	while (uk * uk <= A)
 	{
 	 	ll step = 1;
 	 	while (A % uk == 0) A /= uk, step *= uk;
 	 	if (step != 1) spis.pb(step);
 	 	uk++;
 	}
 	if (A != 1) spis.pb(A);

 	int sz = (int) spis.size();
 	for (int mask = 0; mask < (1 << sz); mask++)
 	{
 	 	ll fir = 1, sec = 1;
 	 	for (int i = 0; i < sz; i++)
 	 		if (((mask >> i) & 1) != 0) fir *= spis[i];
 	 		else sec *= spis[i];
 	 	ll d = nod(fir, sec);

 	 	if (X <= 0) X += ((-X) / sec + 1) * sec;
 	 	X %= sec;
 	 	if (X == 0) X = sec;
 	 	answer = min(answer, X * fir);
 	}
 	cout << answer << '\n';
 	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define uid uniform_int_distribution<lli>
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>
#define endl "\n"
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class my>
inline my aabs (const my& a)   { return (a > 0)  ? a : -a;         }
inline lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
inline lli LSOne(lli k)        { return (k&(-k));                  }

inline int inv(lli o, int m = mod) {
  int b = m, u = 0, v = 1, t, a=o%m;
  while (a) {
    t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += m;
  return u;
}
inline int add(const int &a, const int &b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(const int &a, const int &b) { return a - b < 0 ? a - b + mod : a - b; }
inline int mul(const int &a, const int &b) { return int(a * 1ll * b % mod); }
inline int _div(const int &a, const int &b) { return mul(a, inv(b)); }
inline int pow(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = mul(ans, a);
        a = mul(a, a);
        b >>= 1;
    }
    return ans;
}

int fac[100050], infac[100050];
int nCk (int n, int k)
{
    if(n<0||k<0||n<k) return 0;
    return mul(fac[n],mul(infac[k],infac[n-k]));
}

void solve()
{
    lli n=0, m=0, k=0, q=0, temp=0, u=0, v=0, ans=0, ans1=0, ans2=0, val=0, mini=INF, maxi=-INF;
    cin>>n>>k;
    fol(i,1,k+1)
    {
        u=nCk(k-1,i-1);
        v=nCk(n-k+1,i);
        cout<<mul(u,v)<<endl;
    }
}

int main()
{
    fastio cout<<endl;
    int t=1;
    fac[0]=1;
    fol(i,1,2050) fac[i]=mul(fac[i-1],i);
    fol(i,0,2050) infac[i]=inv(fac[i]);
    //cin>>t;
    while(t--)
        solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
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;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    using graph=vector<vector<int>>;
    int n,m; cin >> n >> m;
    graph r(n+1);
    rep(i,m){
        int a,b; cin >> a >> b;
        r[a].push_back(b);
        r[b].push_back(a);
    }
    int ans=0;
    vector<bool> rooted(n+1,false);
    for(int i=1;i<=n;i++){
        if(rooted[i]==false){
            rooted[i]=true;
            queue<int> q;
            for(int e:r[i]){
                if(rooted[e]==false)  q.push(e);
            }
            while(!q.empty()){
                int a=q.front();
                rooted[a]=true;
                q.pop();
                for(int e:r[a]){
                    if(rooted[e]==false) q.push(e);
                }
            }
            ans++;
        }
    }
    cout << ans-1 << endl;
}




Measured memory_bytes: 8468
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s;cin >> s;
  cout << s.substr(0,s.length()-8) << endl;
  return 0;
}


Measured memory_bytes: 256
from itertools import combinations, product
N, M = map(int, input().split())
S = []
for i in range(M):
    l = [int(i)-1 for i in input().split()]
    S.append(l[1:])

P = [int(i) for i in input().split()]

ans = 0
for l in product([0,1], repeat=N):
    count = 0
    for p, s in zip(P, S):
        if sum([l[a] for a in s]) % 2 == p:
            count += 1
    if count == M:
        ans += 1
print(ans)

Measured memory_bytes: 3064
import scala.io.StdIn._
import scala.annotation.tailrec
import scala.collection._

object Main {

  class Sieve(val n: Int){
    private[this] val top = (n - 3) / 2 + 1
    private[this] val (cmpsts, sqrtLmtNdx) = (new Array[Int]((top >>> 5) + 1), (Math.sqrt(n).toInt - 3) / 2)

    def isCmpst(ci: Int): Boolean = (cmpsts(ci >>> 5) & (1 << (ci & 31))) != 0
    def setCmpst(ci: Int): Unit = cmpsts(ci >>> 5) |= 1 << (ci & 31)

    @tailrec
    private def cull(cmpstId: Int, p: Int): Unit = {
      if(cmpstId <= top){
        setCmpst(cmpstId)
        cull(cmpstId + p, p)
      }
    }

    @tailrec
    private def get(cndId: Int): Unit = {
      if(cndId <= sqrtLmtNdx){
        if(!isCmpst(cndId)){
          val p = 2 * cndId + 3
          cull((p * p - 3) >>> 1, p)
        }
        get(cndId + 1)
      }
    }

    @tailrec
    private def next(cndId: Int): Int =
      if ((cndId > top) || !isCmpst(cndId)) 2 * cndId + 3 else next(cndId + 1)

    def exec: Iterator[Int] = {
      get(0)
      Iterator.single(2) ++ Iterator.iterate(3)(p => next((p - 1) >>> 1)).takeWhile(_ <= n)
    }
  }

  @tailrec
  def loop(s: String){
    if(s != null){
       val Array(n,_*) = s.split(" ").map(_.toInt)
       if(n<2) println(0)
       else println(new Sieve(n).exec.size)
       loop(readLine)
    }
  }

  def main(args: Array[String]): Unit = loop(readLine)
}

Measured memory_bytes: 65048
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false); cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int nmax = 1e5 + 10;
int n;
ll C;
ll x[nmax];
ll v[nmax];
ll f1[nmax];
ll f2[nmax];
int main() {
    IO;
    cin >> n >> C;
    v[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> v[i];
        v[i] += v[i - 1];
    }
    v[n + 1] = v[n];
    f1[0] = 0;
    for (int i = 1; i <= n; i++) 
        f1[i] = max(f1[i - 1], v[i] - x[i]);
    f2[n + 1] = 0;
    for (int i = n; i >= 1; i--) 
        f2[i] = max(f2[i + 1], v[n] - v[i - 1] - (C - x[i]));
    ll ans = 0;
    for (int i = 1; i <= n + 1; i++) {
        int j = i - 1;
        ll value = f1[j] + v[n] - v[i - 1];
        ll dis;
        if (i == n + 1) dis = 0;
        else dis = 2 * (C - x[i]);
        ans = max(ans, value - dis);
    }
    for (int i = 0; i <= n; i++) {
        int j = i + 1;
        ll value = f2[j] + v[i];
        ll dis;
        if (i == 0) dis = 0;
        else dis = 2 * x[i];
        ans = max(ans, value - dis);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;

int main(void)
{
	int a, b, c, x; cin >> a >> b >> c >> x;
	int cnt = 0;

	for (int i = 0; i <= a; i++)
	{
		for (int j = 0; j <= b; j++)
		{
			for (int k = 0; k <= c; k++)
			{
				if (i * 500 + j * 100 + k * 50 == x) cnt++;
			}
		}
	}

	cout << cnt << endl;
}


Measured memory_bytes: 256
N=int(input())
D=[]
x=[]
D = [[0 for i in range(2)] for j in range(N)]#N×"2"の行列Dを作る
for i in range(0,N):
    x=input().split(" ")
    for j in range(0,2):#i行目の成分を入力
        D[i][j]=int(x[j])

D.sort(key=lambda p:p[1])#2列目の成分でソート

x=0
for i in range(0,N):
    x=x+D[i][0]#経過時間
    y=D[i][1]#締め切り時刻
    if x>y:
        n=1
        break
    else:
        n=0
if n==1:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 41240
void main() {
	auto c = readMatrix!char(3, 3);
	foreach(i; 0..3) c[i][i].write;
	writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[]args){
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		
		
		int count = 0;
		
		
		for(int i = 1;i<=B;i++){
			if(A*i%B==C){
				count =1;
			}
			
		}
		
		
		System.out.println(count==1?"YES":"NO");
		
		
		
	}

}


Measured memory_bytes: 23380
import bisect
N=int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
alist.sort()
blist.sort()
clist.sort()

answer=0
ai,ci=0,0
for bi in range(N):
  while(ai<N and alist[ai]<blist[bi]):
    ai+=1
  while(ci<N and blist[bi]>=clist[ci]):
    ci+=1
  #print(ai,bi,ci)
  answer+=ai*(N-ci)

print(answer)

Measured memory_bytes: 23360
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



int n;
int h[100000][3];
int dp[100001][3];


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

	cin >> n;
	rep(i,n) {
		rep(j, 3)cin >> h[i][j];
	}

	rep(i, n + 1)rep(j, 3)dp[i][j] = -INF;
	rep(j, 3)dp[0][j] = 0;

	rep(i,n) rep(j,3){
		rep(k, 3) if (j != k) {
			dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + h[i][k]);
		}
	}
	cout << *max_element(dp[n], dp[n] + 3) << endl;



	return 0;
}


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


import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
#a,b,x = [int(i) for i in readline().split()]


ans = n+100
for i in range(1,1000001):
    if n%i == 0:
        c = i + n//i -2
        if c < ans: ans = c
    

print(ans)
        


Measured memory_bytes: 2940
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   B_How_Many_ways.c                                  :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: mkosaka <42tokyo_jan2020_pisciner>         +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/05 11:57:49 by mkosaka           #+#    #+#             */
/*   Updated: 2020/02/05 11:57:49 by mkosaka          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <stdio.h>
#include <stdlib.h>

int		combination_sum_equals(int n, int sum)
{
	int count;
	int index[3];

	count = 0;
	index[0] = 1;
	while (index[0] <= n - 2)
	{
		index[1] = index[0] + 1;
		while (index[1] <= n -1)
		{
			index[2] = index[1] + 1;
			while (index[2] <= n)
			{
				if (index[0] + index[1] + index[2] == sum)
					count += 1;
				index[2]++;
			}
			index[1]++;
		}
		index[0]++;
	}
	return (count);
}

void	print_integers(int *integers, int ammounts)
{
	int i;

	i = 0;
	while (i < ammounts)
	{
		printf("%d\n", integers[i]);
		i++;
	}
}

int		main(void)
{
	int *counts;
	int n;
	int x;
	int i;

	counts = (int *)malloc(sizeof(int) * 300);
	i = 0;
	while (1)
	{
		scanf("%d %d", &n, &x);
		if (n == 0 && x == 0)
			break;
		counts[i] = combination_sum_equals(n, x);
		i++;
	}
	print_integers(counts, i);
	return (0);
}



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

using namespace std;

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



int main(){
  while(1){
    int n,m,p,sum=0;
    cin >> n >> m >> p;
    m--;
    if(!n)break;
    vector<int> x(n);
    rep(i,n)cin>>x[i];
    rep(i,n)sum+=x[i];
    if(x[m]==0)cout << 0 << endl;
    else cout << (int)((double)sum*(100-p)/x[m]) << endl;
  }

  return 0;
}



Measured memory_bytes: 3108
#include <stdio.h>
#include <string.h>
int main(void)
{
    char taro[100],hanako[100];
    int n,i,t_point=0,h_point=0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%s %s",taro,hanako);
        if(strcmp(taro,hanako)>0) t_point+=3;
        else if(strcmp(taro,hanako)<0) h_point+=3;
        else if(strcmp(taro,hanako)==0)
        {
            t_point++; h_point++;
        }
    }
    printf("%d %d\n",t_point,h_point);
    
    return 0;
}



Measured memory_bytes: 2104
#include<iostream>
#include<algorithm>
#include<functional>
#include<climits>

using namespace std;


template<class S=int, class T=std::less<S>, S nil=INT_MAX>
class RMQ2D{
	int h,w;
	S *datrmq;

	static int calcsize(int n){
		int res=1;
		while(res<n)res<<=1;
		return res;
	}
	void xbuild(int y,int n,const S a[]){
		S *dat=datrmq+y*(2*w-1);
		for(int i=0;i<n;i++)dat[w-1+i]=a[i];
		for(int i=n;i<w;i++)dat[w-1+i]=nil;
		for(int i=w-2;i>=0;i--){
			dat[i]=std::min(dat[i*2+1],dat[i*2+2],T());
		}
	}
	void xupdate(S *dat,int x,int a){
		x+=w-1;
		dat[x]=a;
		while(x>0){
			x=(x-1)/2;
			dat[x]=std::min(dat[x*2+1],dat[x*2+2],T());
		}
	}
	void yupdate(int y,int x,int a){
		y+=h-1;
		while(y>0){
			y=(y-1)/2;
			xupdate(datrmq+y*(2*w-1),x,a);
		}
	}
	S xquery(const S *dat,int a,int b,int k,int l,int r)const{
		if(r<=a||b<=l)return nil;
		if(a<=l&&r<=b)return dat[k];
		else{
			S vl=xquery(dat,a,b,k*2+1,l,(l+r)/2);
			S vr=xquery(dat,a,b,k*2+2,(l+r)/2,r);
			return std::min(vl,vr,T());
		}
	}
	S yquery(int ys,int ye,int k,int l,int r,int xs,int xe)const{
		if(r<=ys||ye<=l)return nil;
		if(ys<=l&&r<=ye)return xquery(datrmq+k*(2*w-1),xs,xe, 0,0,w);
		else{
			S vl=yquery(ys,ye,k*2+1,l,(l+r)/2,xs,xe);
			S vr=yquery(ys,ye,k*2+2,(l+r)/2,r,xs,xe);
			return std::min(vl,vr,T());
		}
	}
public:
	RMQ2D(int h,int w,const S a[]){
		S *dat;
		int n=h,m=w;
		h=this->h=calcsize(h);
		w=this->w=calcsize(w);
		datrmq=new S[(2*h-1)*(2*w-1)];
		dat=new S[2*w-1];
		for(int i=0;i<w;i++)dat[i]=nil;
		for(int i=0;i<n;i++)xbuild(h-1+i,m,a+i*m);
		for(int i=n;i<h;i++)xbuild(h-1+i,m,dat);
		for(int i=h-2;i>=0;i--){
			const S *a=datrmq+(i*2+1)*(2*w-1);
			const S *b=datrmq+(i*2+2)*(2*w-1);
			S *c=datrmq+i*(2*w-1);
			for(int j=0;j<2*w-1;j++){
				c[j]=std::min(a[j],b[j],T());
			}
		}
		delete[] dat;
	}
	~RMQ2D(){
		delete[] datrmq;
	}
	void update(int y,int x,int a){
		yupdate(y,x,a);
	}
	S query(int ys,int ye,int xs,int xe)const{//[ys,ye)+[xs,xe)の最小(大)値
		return yquery(ys,ye,0,0,h,xs,xe);
	}
};



unsigned int g[1000000];
int main(){
	int r,c,q;
	while(cin>>r>>c>>q,r|c|q){
		for(int i=0;i<r*c;i++)cin>>g[i];
		RMQ2D<unsigned int,std::less<unsigned int>,~0u> rmq(r,c,g);
		for(int i=0;i<q;i++){
			int y1,x1,y2,x2;
			cin>>y1>>x1>>y2>>x2;
			cout<<rmq.query(y1,y2+1,x1,x2+1)<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 37668
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

const int mod=1e9+7;

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    cout << (c>=a+b+1?a+2*b+1:b+c) << endl;
}


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

class SA{
public:
  string S;
  int n;
  vector<int> sa;
  
  SA():n(-1){}
  SA(string S):S(S),n(S.size()),sa(n){  
    vector<int> rnk(n);
    vector<int> tmp(n);
    for(int i=0;i<n;i++) sa[i]=i;
    for(int i=0;i<n;i++) rnk[i] = S[i];
    
    //k文字についてソートされているところから、2k文字でソート
    for(int Len=1;Len<=n;Len*=2){
      
      //(rnk[i],rnk[i+k])と(rnk[j],rnk[j+k])を比較
      auto compare_sa=[&](const int &i,const int &j){
        if(rnk[i]!=rnk[j])return rnk[i]<rnk[j];
        int ri=i+Len<n?rnk[i+Len]:-1;
        int rj=j+Len<n?rnk[j+Len]:-1;
        return ri<rj;
      };
      
      sort(sa.begin(),sa.end(),compare_sa);

      //いったんtmpに次のランクを計算して、rnkに代入
      for(int i=1;i<n;i++)
        tmp[sa[i]] = tmp[sa[i-1]] + compare_sa(sa[i-1],sa[i]);
      rnk = tmp;
    }
  }

  int lower_bound(string T){
    assert(n >= 0);
    int L=-1,R=S.length();
    while(L+1<R){
      int M = (L+R)/2;
      S.compare(sa[M],T.size(),T)<0? L = M:R = M;
    }
    return R;
  } 

  int upper_bound(string T){return lower_bound(T+char('z'+ 1));} 
  int count(string T){return upper_bound(T) - lower_bound(T);};
};

int main(){
  string s;
  cin>>s;
  SA sa(s);
  
  int q;
  cin>>q;
  while(q--){
    string t;
    cin>>t;
    int ans = sa.count(t) != 0;
    printf("%d\n",ans);
  }
  
}



Measured memory_bytes: 16588
# Traveling
import sys
import numpy as np
input = sys.stdin.readline

N = int(input())
memo = np.array([[0, 0, 0], []])
for _ in range(N):
  memo[1] = np.array([int(x) for x in input().split()])
  dt, dx, dy = np.abs(memo[0]-memo[1])
  d = dx + dy
  if dt < d:
    print('No')
    exit()
  else:
    if (dt - d)%2 != 0:
      print('No')
      exit()
    else:
      memo = np.array([memo[1], []])
print('Yes')



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

int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }

  ll cnt = 0;
  for (auto mpp : mp) {
    if (mpp.second == 1) continue;
    ll m = mpp.second;
    ll c = m * (m - 1) / 2;
    cnt += c;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>

using ll = long long;
using P = std::pair<ll, ll>;


#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(),i.end()
#define debug(i) std::cout << i << "\n"



const int INF = 100000000;
const ll MOD = 1000000007;

ll pow_mod(ll x, ll y, ll mod)
{
	if (y == 0)
		return 1;
    if(y%2){
        return (x*pow_mod(x,y-1,mod))%mod;
    }else{
        return pow_mod(x*x,y/2,mod);
    }
}

int main()
{
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!

  ll a, b;
  std::cin >> a >> b;
  if((a-b)%2==0){
    std::cout << (a + b) / 2;
  }else{
    std::cout << "IMPOSSIBLE";
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
double factorial(double x);

int main(void)
{
	double n, ans;
	scanf("%lf", &n);
	ans = factorial(n);
	printf("%.f\n", ans);
	
	return 0;
}

double factorial(double x){
	if(x > 0)
	return x * factorial(x - 1);
	else
	return 1;
}

Measured memory_bytes: 648
def avi_chk(X,avi_list):
    for a in avi_list:
        if a<X:
            return False
    return True

def t1():
    import numpy as np

    N,M,X=map(int,input().split())
    C_list=[]
    avility=[]
    for i in range(N):
        c=list(map(int,input().split()))

        avility.append(c)
        
    min_v=-1
    for i in range(2**N):
        v=0
        now_avi=np.zeros(M)
        for j in range(N):
            if((i>>j)&1):
                now_avi+=avility[j][1::]
                v+=avility[j][0]
        if avi_chk(X,now_avi):
            if min_v==-1:
                min_v=v
            elif min_v>v:
                min_v=v
    print(min_v)

            
        
                

      
if __name__ == '__main__':
    t1()
    

Measured memory_bytes: 27192
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    # A = 'abracadabra'
    # a = set()
    # a.add(A)
    # for i in range(11):
    #     for j in range(i,11):
    #         tmp = A[i:j+1][::-1]
    #         if i > 0:
    #             tmp = A[:i] + tmp
    #         if j < 10:
    #             tmp = tmp + A[j+1:]
    #         if tmp in a:
    #             print(i,j,tmp)
    #         a.add(tmp)
    # print(len(a))
    A = input()
    N = len(A)
    l = Counter(A)
    ans = N*(N+1)//2 + 1 - N
    for x in l.values():
        ans -= x*(x-1)//2
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9580
#include <iostream>
#include <map>

using namespace std;

template<long long mod>
long long fact(int i) {
	static map<int, long long> memo;
	if (memo[i] > 0) return memo[i];
	if (i == 0) return 1LL;
	return (memo[i] = i * fact<mod>(i - 1) % mod);
}

template<long long mod>
long long solve(int N, int M) {
	if (M > N) swap(N, M);
	if (N - M > 1) return 0;
	if (N == M + 1) 
		return fact<mod>(N) * fact<mod>(M) % mod;
	return fact<mod>(N) * fact<mod>(M) % mod * 2 % mod;
}

int main(void) {
	int N, M;
	cin >> N >> M;
	cout << solve<1000000007LL>(N, M) << endl;
	return 0;
}

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

public class Main {
  private static boolean solve(int a, int b, char[] cs) {
    for (int i = 0; i < cs.length; i++) {
      boolean isHyphen = cs[i] == '-';
      boolean isHyphenPosition = i == a;
      if (isHyphen != isHyphenPosition) {
        return false;
      }
    }
    return true;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int a = reader.nextInt();
    int b = reader.nextInt();
    char[] cs = reader.nextCharArray();
    out.println(solve(a, b, cs) ? "Yes" : "No");
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
 
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define debug(x) cout<<#x<<": "<<x<<endl
 
#define ld double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
 
#define INF 1000000000000000000

ll h,w;
char a[1001][1001];
ll dp[1001][1001];
bool vis[1001][1001];
ll mod = 1000000007;

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

    cin >> h >> w;
    fr(i,1,h)
    {
        fr(j,1,w)
        {
            cin >> a[i][j];
            vis[i][j] = 0;
        }
    }

    queue<pair<ll, ll> > q;
    q.push(mp(h,w));
    dp[h][w] = 1;

    while(!q.empty())
    {
        ll x = q.front().ff;
        ll y = q.front().ss;
        q.pop();

        if(x>h || x<1 || y>w || y<1)
            continue;

        if(vis[x][y])
            continue;

        vis[x][y] = 1;
        if(a[x][y]=='#')
            continue;

        if(x<h)
        {
            dp[x][y] = ((dp[x][y]%mod) + dp[x+1][y]%mod)%mod;
        }
        if(y<w)
            dp[x][y] = ((dp[x][y]%mod) + (dp[x][y+1]%mod))%mod;

        q.push(mp(x-1,y));
        q.push(mp(x,y-1));

    }

    cout << dp[1][1] << endl;
}

Measured memory_bytes: 10112
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#pragma warning( disable:4996 )
using namespace std;

#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define MIN(a, b) ((a) < (b) ? (a) : (b))

int n;
int x[9];
int y[9];

/*double rec(int k, int now) {
	if (k == n)return now;
	double sum = 0.0;
	for(int i=0;i<n;)
}*/

int main(void) {
	/*int r;
	scanf("%d", &r);
	printf("%d\n", r * r);*/
	/*int n;
	char s[101];
	scanf("%d", &n);
	scanf("%s", s);
	if (n >= 2 && n % 2 == 0) {
		int half = n / 2;
		for (int i = 0; i < half; i++) {
			if (s[i] != s[half + i]) {
				printf("No\n");
				return 0;
			}
		}
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}*/
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &x[i], &y[i]);
	}
	double ans = 0.0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j)continue;
			ans += sqrt(((double)x[i] - x[j]) * ((double)x[i] - x[j]) + ((double)y[i] - y[j]) * ((double)y[i] - y[j]));
		}
	}
	/*int p = 1;
	for (int i = 1; i <= n-2; i++) {
		p *= i;
	}
	p *= (n - 1) * 2;
	int nb = 1;
	for (int i = 1; i <= n; i++) {
		nb *= i;
	}*/

	
	//ans /= p;
	printf("%lf\n", ans/n);
	
	return 0;
}

Measured memory_bytes: 128
//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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 ) * } } ; }
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" ) } ; }
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 ) * } } ; }
//入力マクロここまで

use std::cmp::*;
const INI: usize = 1_000_000_000_000_000;

fn main() {
    input! {
        h: usize,
        n: usize,
        abs: [(usize,usize);n],
    }

    let (a, b): (Vec<usize>, Vec<usize>) = abs.iter().cloned().unzip();

    let a_max = *a.iter().max().unwrap() as usize;
    let mut dp = vec![INI; h + a_max];

    dp[0] = 0;

    for i in 1..h + a_max {
        for j in 0..n {
            dp[i] = if i >= a[j] {
                min(dp[i], dp[i - a[j]] + b[j])
            } else {
                dp[i]
            }
        }
    }

    println!("{}", dp[h..].iter().min().unwrap());
}


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

struct node
{
	int key;
	node* lc, * rc, * p;
};

node* root = 0;

void insert(int x)
{
	node* pre = root;        //设当前节点为根，以根为起点
	node* temp = pre;        //用来保存当前节点的临时指针

	node* in = (node*)malloc(sizeof(node));
	in->key = x;
	in->lc = 0;
	in->rc = 0;
	in->p = 0;

	while (pre != 0)        //找到将要插入的节点的父节点(当前节点)
	{
		temp = pre;
		if (in->key < pre->key)
			pre = pre->lc;
		else
			pre = pre->rc;
	}
	pre = temp;

	if (pre == 0)           //插入
		root = in;
	else
	{
		if (in->key < pre->key)
			pre->lc = in;
		else
			pre->rc = in;
		in->p = pre;
	}
}

node* Findlater(node* f)
{
	f = f->rc;
	while (f->lc != 0)
		f = f->lc;

	return f;		
}

void Delete(int de)
{
	node* find = root;             
	node* De;              //将要删除的节点
	node* c;               //De的子节点  

	while (find != 0)
	{
		if (de < find->key)
			find = find->lc;
		else if (de > find->key)
			find = find->rc;
		else
		{
			if (find->lc == 0 || find->rc == 0)           //确认将要删除的节点
				De = find;
			else
				De = Findlater(find);
//-------------------------------------------------------------//
			if (De != find)
				find->key = De->key;

			if (De->lc != 0)                      //确认De的子节点
				c = De->lc;
			else
				c = De->rc;

			if (c != 0)
				c->p = De->p;

			if (De->p == 0)
				root = c;
			else
			{
				if (De == De->p->lc)
					De->p->lc = c;
				else
					De->p->rc = c;
			}
			
			break;
		}
	}
}

bool Find(int f)
{
	bool fin = false;

	node* pre = root;
	while (pre != 0)
	{
		if (f < pre->key)
			pre = pre->lc;
		else if (f > pre->key)
			pre = pre->rc;
		else
		{
			fin = true;
			break;
		}

	}

	return fin;
}

void Inorder(node* r)
{
	if (r->lc != 0)
		Inorder(r->lc);

	cout << " " << r->key;
	
	if (r->rc != 0)
		Inorder(r->rc);
}

void Preorder(node * r)
{
	cout << " " << r->key;

	if (r->lc != 0)
		Preorder(r->lc);
	if (r->rc != 0)
		Preorder(r->rc);
}

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

	int n, x;
	string p;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> p;

		if (p == "insert")
		{
			cin >> x;
			insert(x);
		}
		else if (p == "find")
		{
			cin >> x;
			if (Find(x))
				cout << "yes\n";
			else
				cout << "no\n";
		}
		else if (p == "delete")
		{
			cin >> x;
			Delete(x);
		}
		else
		{
			Inorder(root);
			cout << endl;
			Preorder(root);
			cout << endl;
		}
	}

	return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000.0

using namespace std;

struct UnionFind {
  vector<int> data;

  UnionFind(int n){
    data.resize(n+1);
    fill(data.begin(), data.end(), -1);
  }

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

  void unite(int x, int y){
    int rx=root(x);
    int ry=root(y);

    if(rx!=ry){
      if(data[ry] < data[rx])swap(rx, ry);

      data[rx]+=data[ry];
      data[ry]=rx;
    }
  }

  bool same(int x, int y){
    return root(x)==root(y);
  }

  int size(int x){
    return -data[root(x)];
  }
};

int n;
#define MAXN 100

double x[MAXN], y[MAXN], z[MAXN], r[MAXN];
vector<pair<double, pi>> edges;

double square(double n){ return n*n; }

double solve(){
  edges.clear();

  rep(i, n)rep(j, n){
    if(i==j)continue;
 
    double dist = square(x[i]-x[j])+square(y[i]-y[j])+square(z[i]-z[j]);
    dist = pow(dist, 0.5);
    double cost=0.0;
    
    // 非接触
    if( dist > r[i]+r[j] ){
      cost = dist - (r[i]+r[j]);
    // }else if(max<double>(r[i], r[j]) > dist+min<double>(r[i], r[j]) ){
      // 内包
      // cost = max<double>(r[i], r[j]) - (dist+min<double>(r[i], r[j]) );
    }
    edges.push_back({cost, {i, j}});
  }

  sort(edges.begin(), edges.end());

  double result=0.0;
  UnionFind uf(n);
  for(auto p: edges){
    pi pp = p.second;
    if(!uf.same(pp.first, pp.second)){
      result += p.first;
      uf.unite(pp.first, pp.second);
    }
  }
  return result;
}

int main(){

  while(cin>>n){
    if(n==0)break;

    rep(i, n)cin>>x[i]>>y[i]>>z[i]>>r[i];

    cout<<fixed<<setprecision(3)<<solve()<<endl;
  }

  return 0;
}



Measured memory_bytes: 3668
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

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

Measured memory_bytes: 3632
//#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 9;
const int infint = 1e9 + 7;
const int MAXN = 2e5 + 7;
const double eps = 1e-9;
const long double pi = 3.1415926535897932384626433832795;
const long double e = 2.71828182845904523536028747135266;
inline ll read()
{
    ll kr = 1, xs = 0;char ls;ls = getchar();
    while (!isdigit(ls)){
        if (!(ls ^ 45)) kr = -1;
        ls = getchar();
    }
    while (isdigit(ls)){
        xs = (xs << 1) + (xs << 3) + (ls ^ 48);ls = getchar();
    }return xs * kr;
}
// inline __int128 read128()
// {
//     __int128 kr=1,xs=0;char ls;ls=getchar();
//     while(!isdigit(ls)){
//         if(!(ls^45)) kr=-1;ls=getchar();
//     }
//     while(isdigit(ls)){
//         xs=(xs<<1)+(xs<<3)+(ls^48);ls=getchar();
//     }
//     return xs*kr;
// }
inline ull readull()
{
    ull xs = 0;char ls;ls = getchar();
    while (!isdigit(ls))ls = getchar();
    while (isdigit(ls)){
        xs = (xs << 1) + (xs << 3) + (ls ^ 48);ls = getchar();
    }return xs;
}
inline void writeull(ull x)
{
    if (x < 0){
        x *= -1;putchar('-');
    }
    if (x >= 10) writeull(x / 10);
    putchar('0' + x % 10);
}
inline void write(ll x)
{
    if (x < 0){
        x *= -1;putchar('-');
    }
    if (x >= 10) write(x / 10);
    putchar('0' + x % 10);
}
// inline void write(__int128 x){
//     if(x<0){x*=-1;putchar('-');}
//     if(x>=10) write(x/10);
//     putchar('0'+x%10);
// }
///////////////////////////////////////////////////////////////////////////////////////
int main()
{
    // ios_base::sync_with_stdio(0);
    // cin.tie(0),cout.tie(0);
    int t = 1;
    // t = read();
    while (t--)
    {
        int n=read();
        ll x,y;
        ll x1=0,y1=1000000001;
        ll min1=mod,min2=mod,max1=-1,max2=-1;
        for (int i=1;i<=n;i++) {
            x=read(),y=read();
            min1=min(min1,x+y);
            max1=max(max1,x+y);
            min2=min(min2,abs(x-x1)+abs(y-y1));
            max2=max(max2,abs(x-x1)+abs(y-y1));
        }
        cout << max(max1-min1,max2-min2) << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main() {
    int N;
    long long K;
    cin >> N >> K;
    vector<int> as;
    map<int, long long> bs;
    for(int i=0; i<N; i++) {
        int a, b;
        cin >> a >> b;
        if(bs.find(a) == bs.end()) {
            bs[a] = b;
            as.push_back(a);
        } else {
            bs[a] += b;
        }
    }
    sort(as.begin(), as.end());
    for(int i=0; i<N; i++) {
        int a = as[i];
        long long b = bs[a];
        if(K > b) K -= b;
        else {
            cout << a << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
#define MAX 700000 

int BIT[27][MAX];

int query_pre(int c, int x)
{
	int s = 0;
	while(x) s += BIT[c][x], x -= x&-x;
	return s;
}

int query(int l, int r, int c)
{
	return query_pre(c, r) - query_pre(c, l - 1);
}

int update(int c, int p, int v)
{
	while(p <= MAX - 10) BIT[c][p] += v, p += p&-p;
}

int32_t main()
{   
	int n, q;
	string s;
	cin >> n >> s >> q;
	
	for(int i = 0; i < n; i++)
		update(s[i] - 'a', i + 1, 1);
	while(q--)
	{
		int o;
		cin >> o;
		if(o == 1)
		{
			int p;
			char c;
			cin >> p >> c;
			update(s[p - 1] - 'a', p, -1);
			s[p - 1] = c;
			update(s[p - 1] - 'a', p, 1);
		}
		else
		{
			int l, r;
			cin >> l >> r;
			int ans = 0;
			for(int i = 0; i < 26; i++)
				if(query(l, r, i) > 0)
					ans++;
			cout << ans << '\n';
		}
	}
	
	
    return 0;
}

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


void solve(long long A, long long B, long long C){
    if(A == B){
        cout << C << endl;
    }else if(A == C){
        cout << B << endl;
    }else if(B == C){
        cout << A << endl;
    }
}  

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> M;
	vector< int > d;
	for (int i = 1; i * i <= M; i++) {
		if (M % i == 0) {
			d.push_back(i);
			d.push_back(M / i);
		}
	}
	sort(d.rbegin(), d.rend());
	int ans;
	rep(i, d.size()) {
		if (M / d[i] >= N) {
			ans = d[i];
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    ll X, Y, W, H;
    ll p = 1000000007;
    vector<ll> fac, ifac;

    cin >> X >> Y;
    if ((2 * X - Y) % 3 == 0 && (2 * Y - X) % 3 == 0) {
        W = (2 * X - Y) / 3;
        H = (2 * Y - X) / 3;
    }
    else {
        cout << 0 << endl;
        return 0;
    }
    if (W < 0 || H < 0) {
        cout << 0 << endl;
        return 0;
    }

    // calculate factorial and inverse factorial
    fac.push_back(1);
    for (ll i = 1; i <= H + W; i++) {
        ll t = fac[i - 1];
        t *= i;
        fac.push_back(t % p);
    }
    ll fac_t = fac[H + W];
    ll ifac_max = 1;
    for (int i = 0; ((p - 2) >> i) > 0 ; i++) {
        if (((p - 2) >> i) & 1) {
            ifac_max *= fac_t;
            ifac_max %= p;
        }
        fac_t *= fac_t;
        fac_t %= p;
    }
    ifac.push_back(ifac_max);

    for (int i = 1; i <= H + W; i++) {
        ll t = ifac[i - 1];
        t *= H + W - i + 1;
        ifac.push_back(t % p);
    }
    reverse(ifac.begin(), ifac.end());

    ll ans = fac[W + H];
    ans = (ans * ifac[W]) % p;
    ans = (ans * ifac[H]) % p;
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 20584
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long N, K;
    scan(N, K);
    auto A = aryread();
    long head;
    long tail;

    foreach (i; 0 .. N)
        foreach (j; 0 .. N)
            if (A[j] < A[i])
            {
                if (i < j)
                    head++;
                tail++;
            }
    long ans = (head * K) % MOD;
    long mul = ((K - 1) * K / 2) % MOD;
    ans = (ans + (mul * tail)) % MOD;
    writeln(ans);
}


Measured memory_bytes: 380
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = []
c = 0
x.sort()
for i in range(m - 1):
    y.append(x[i + 1] - x[i])
y.sort()
if n < m:
    for i in range(n - 1):
        c += y[m - 2 - i]
    print(x[m - 1] - x[0] - c)
else:
    print(0)

Measured memory_bytes: 13960
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def is_nth_bit_set(x, n):
    if x & (1 << n):
        return True
    else:
        return False


def main():
    N, M, X = map(int, input().split())
    A = [0] * M
    C = []
    A = []
    for _ in range(N):
        a = list(map(int, input().split()))
        C.append(a[0])
        A.append(a[1:])

    ans = INF
    for pattern in range(2 ** N):
        money = 0
        status = [0] * M
        for i in range(N):
            if is_nth_bit_set(pattern, i):
                money += C[i]

                for j in range(M):
                    status[j] += A[i][j]

        for i in range(M):
            if status[i] < X:
                break
        else:
            if money < ans:
                ans = money

    if ans == INF:
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9260
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=15;
int n;
char s[N];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	if(n&1)
	{
		printf("No");
		return 0;
	}
	for(int i=1;i<=n;i+=2)
		if(s[i]!='h'||s[i+1]!='i')
		{
			printf("No");
			return 0;
		}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 3752