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

public class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int a, b;

    while (true) {
      a = scanner.nextInt();
      b = scanner.nextInt();
      if (a == 0 && b == 0) break;
      for (int i = 0; i < a; ++i) {
        for (int j = 0; j < b; ++j) System.out.printf("#");
        System.out.println();
      }
      System.out.println();
    }
  }
}


Measured memory_bytes: 57472
H,W=(int(x) for x in input().split())
while H!=0 or W!=0:
    for i in range(H):
        if i==0 or i==H-1:
            print("#"*W)
        else:
            print("#"+"."*(W-2)+"#")
    H,W=(int(x) for x in input().split())
    print("")


Measured memory_bytes: 5620
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define rev(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = INT_MAX;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ O(logN)
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//





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

    vector<ll> dp(n);
    rep(i,n) dp[i] = INF;
    dp[0] = 0;
    dp[1] = max(h[0] - h[1], h[1] - h[0]);
    for (int i = 2; i < n; ++i) {
        dp[i] = min(dp[i-1] + max(h[i] - h[i-1], h[i-1] - h[i]), dp[i-2] + max(h[i] - h[i-2], h[i-2] - h[i]));
    }

    out(dp[n-1]);
    
    return 0;
}






Measured memory_bytes: 1792
K = int(input())
ans = [0]
count = 0
def f(n):
    tmp = str(n)
    if int(n) > 3234566667:
        return
    else:
        ans.append(int(n))
    f(str(tmp)+tmp[-1])
    if int(tmp[-1])-1 >= 0:
        f(str(tmp)+str(int(tmp[-1])-1))
    if int(tmp[-1])+1 <= 9:
        f(str(tmp)+str(int(tmp[-1])+1))
f(1)
f(2)
f(3)
f(4)
f(5)
f(6)
f(7)
f(8)
f(9)
ans.sort()
print(ans[K])

Measured memory_bytes: 7444
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int& i : v) cin >> i;

    vector<int> ans;
    REP(i, n){
        if(v[i] > i+1){
            cout << -1 << endl;
            return 0;
        }
        ans.insert(ans.begin() + v[i] - 1, v[i]);
    }

    for(auto i : ans){
        cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n)   for(int i=0;i<(n);++i)
#define ALL(v)     (v).begin(),(v).end()
#define debug(x)   cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

int main(){
	int x;
	cin>>x;
	
	cout<<(x?0:1)<<endl;	
}

Measured memory_bytes: 3616
n = int(input())
A = list(map(int, input().split()))


A.sort(reverse=True)
confort = A[0]

if (n % 2 == 0):
    for i in range(1, int(n/2)):
        confort += 2*A[i]
else:
    for i in range(1, int((n+1)/2)):
        confort +=2*A[i]
    confort -= A[int((n+1)/2-1)]


print(confort)

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

using namespace std;

typedef long long int ll;

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

  int n, k;
  cin >> n >> k;
  vector < pair < int, int > > v;
  for(int i = 0; i < n; i++){
    int t, d;
    cin >> t >> d;
    v.push_back({d, t});
  }

  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  priority_queue < int, vector < int >, greater < int > > q;
  vector < bool > used(n + 1, false);
  ll y = 0, x = 0;
  for(int i = 0; i < k; i++){
    y += v[i].first;
    if(!used[v[i].second]){
      used[v[i].second] = true;
      x++;
    }else{
      q.push(v[i].first);
    }
  }

  ll ans = y + x * x;
  for(int i = k; i < n && !q.empty(); i++){
    if(used[v[i].second]) continue;
    x++;
    y -= q.top();
    q.pop();
    y += v[i].first;
    used[v[i].second] = true;
    ans = max(ans, x * x + y);
  }

  cout << ans << '\n';
}


Measured memory_bytes: 1400
#include <iostream>
#include <vector>

using namespace std;

typedef int Weight;
struct Edge {
	int src, dst;
	Weight weight;
	Edge(int src, int dst, Weight weight) :
		src(src), dst(dst), weight(weight) { }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef pair<Weight, int> Result;
Result visit(int p, int v, const Graph &g) {
	Result r(0, v);
	for (auto &e : g[v]) if (e.dst != p) {
		Result t = visit(v, e.dst, g);
		t.first += e.weight;
		if (r.first < t.first) r = t;
	}
	return r;
}
Weight diameter(const Graph &g) {
	Result r = visit(-1, 0, g);
	Result t = visit(-1, r.second, g);
	return t.first;
}

int main()
{
	int N;
	cin >> N;
	Graph g(N);
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		g[a].emplace_back(a, b, 1);
		g[b].emplace_back(b, a, 1);
	}

	int d = diameter(g);

	if (d % 3 == 1) {
		cout << "Second" << endl;
	}
	else {
		cout << "First" << endl;
	}
}


Measured memory_bytes: 26752
import numpy as np

n, k = list(map(int, input().split()))
h = np.array(list(map(int, input().split())))

npmin = np.min
npabs = np.abs

k = min(k, n-1)
dp = np.zeros(n+1)

for i in range(2, k+1):
    dp[i] = npmin(dp[1:i] + npabs(h[i-1] - h[0:i-1]))

for i in range(k+1, n+1):
    dp[i] = npmin(dp[i-k:i] + npabs(h[i-1] - h[i-k-1:i-1]))
    
print(int(dp[n]))

Measured memory_bytes: 22816
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<bitset>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
 int s[100000][40];
 int x[40]={};
 int k[40];
/* int count_digit(long long N){
long long t=N;
int c=0;
    while(t>0){
        t/=2;
        c++;
    }
    return c;



}
*/
void encord1(long long N,int k){
    long long  x=N;
    rep(i,40){
    s[k][i]=x%2;
    x-=s[k][i];
    x=x/2;
    }
    
}

void encord2(long long N){
    long long  x=N;
    rep(i,40){
    k[i]=x%2;
    x-=k[i];
    x=x/2;
    }
    
}

long long  decord(int x[]){
long long t=1;
long long Key=0;
rep(i,40){
Key+=x[i]*t;
t*=2;
}
return Key;

}
int main(){


long long N,K;
cin >> N >>K;
 long long A[N];
 
long long M=0;
 rep(k,N){
cin >> A[k];
encord1(A[k],k);
 }   
encord2(K+1);

long long r;
long long p;
long long Answer=0;
//最大を実現するxを確定させる
int x[40];//各桁0か1

int t,d=0;
for(int i=39;i>=0;i--){
    x[i]=k[i];//kと同じ二進数を表す配列を取得
if(d==0 && k[i]==1){
    t=i;
    d++;
}
}
int count=0;
    for(int m=t;m>=0;m--){
        if(k[m]==1){
            x[m]=0;
        }
        else{
            x[m]=0;
            continue;
        }
        for(int i=0;i<m;i++){
            count=0;
            rep(l,N){
                if(s[l][i]==1){
                    count++;//ビットが1の数をカウント
                }
            }
            if(2*count>N){//半分より多ければ0にする。
                x[i]=0;
            }
            else{
                x[i]=1;
            }
        }
        p=decord(x);
        bitset<40>b=p;
        rep(l,N){
         bitset<40>a=A[l];
         bitset<40>result=a^b;
         r=result.to_ullong();//二進数から10進数への変換
         M+=r;
        }
    Answer=max(Answer,M);
    M=0;
    x[m]=1;

    }
        
    
 

 cout <<Answer<<endl;





 return 0;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n,k;cin>>n>>k;
  int a=1;
  REP(i,n)a=min(a*2, a+k);
  P(a);
  return 0;
}


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

int main(void) {
    int N, R;
    int ans;
    
    cin >> N >> R;
    
    if (N >= 10) {
        ans = R;
    } else {
        ans = R + 100 * (10 - N);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) = yorukatsu14d()

fun yorukatsu14d() {
    val q = readLine()!!.toInt()
    val queries = (1..q).map {
        readLine()!!.split(' ').map { it.toInt() }.let { it[0] to it[1] }
    }

    val cSum = LongArray(100010)
    for (i in 3 until cSum.lastIndex) {
        cSum[i] = cSum[i - 1] +
                if (i % 2 != 0 && isPrime(i.toLong()) && isPrime((i + 1) / 2L)) 1 else 0
    }

    val answer = queries.map {
        val (left, right) = it
        cSum[right] - cSum[left - 1]
    }.joinToString(System.lineSeparator())

    println(answer)
}

private fun isPrime(n: Long): Boolean {
    val sqrt = Math.sqrt(n.toDouble()).toLong()
    for (i in 2..sqrt) if (n % i == 0L) return false
    return true
}


Measured memory_bytes: 64612
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;

int main()
{
    int X,Y,Z,K;
    std::cin >> X>>Y>>Z>>K;
    std::vector<bint> as(X);
    std::vector<bint> bs(Y);
    std::vector<bint> cs(Z);
    for (int i = 0; i < X; i++) {
        std::cin >> as.at(i);
    }
    for (int i = 0; i < Y; i++) {
        std::cin >> bs.at(i);
    }
    for (int i = 0; i < Z; i++) {
        std::cin >> cs.at(i);
    }
    std::sort(as.begin(), as.end(), std::greater<bint>());
    std::sort(bs.begin(), bs.end(), std::greater<bint>());
    std::sort(cs.begin(), cs.end(), std::greater<bint>());
    std::vector<bint> absum{};
    std::vector<bint> absum_long{};
    for (auto a : as) {
        for (auto b : bs) {
            absum_long.emplace_back(a + b);
        }
    }
    std::sort(absum_long.begin(), absum_long.end(), std::greater<bint>());
    std::copy(absum_long.begin(), absum_long.begin() + std::min({static_cast<int>(absum_long.size()), K}), std::back_inserter(absum));
    std::vector<bint> abcsum{};
    for (auto ab : absum) {
        for (auto c : cs) {
            abcsum.emplace_back(ab + c);
        }
    }
    std::sort(abcsum.begin(), abcsum.end(), std::greater<bint>());
    for (int i = 0; i < K; i++) {
        std::cout << abcsum.at(i) << std::endl;
    }
    return 0;
}

Measured memory_bytes: 199004
s = input()
s =  s.split()

h = int(s[0])
w = int(s[1])
if w == 1 or h == 1:
    print(1)
else: 
	r = (h*w+1) /2 if h %2 !=0 and w %2 !=0 else h*w/2
	print(int(r))

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		String line = sc.nextLine();
		while (sc.hasNext()) {
			line += sc.nextLine();
		}
		int len = 'z'-'a'+1;
		int cnt[] = new int[len];
		for (int i = 0; i < line.length(); i++) {
			char c = line.charAt(i);
			if (c >= 'a' && c <= 'z') {
				cnt[c-'a']++;
			}
			if (c >= 'A' && c <= 'Z') {
				cnt[c-'A']++;
			}
		}
		for (int i = 0; i < len; i++) {
			char c = (char)('a' + i);
			System.out.println(c + " : " + cnt[i]);
		}
	}
}



Measured memory_bytes: 26196
#include <iostream>

int main () {
  char c;
  std::cin >> c;
  if (c >= 'A' && c <= 'Z') {
    std::cout << 'A' << std::endl;
  } else if (c >= 'a' && c <= 'z') {
    std::cout << 'a' << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> c(26),t(26);
  for(int i=0;i<26;i++){
    t[i]=51;
  }
  for(int i=0;i<n;i++){
    cin >> s[i];
    for(int j=0;j<s[i].size();j++){
      c[s[i][j]-'a']++;
    }
    for(int j=0;j<26;j++){
      t[j]=min(t[j],c[j]);
      c[j]=0;
    }
  }
  for(int i=0;i<26;i++){
    if(t[i]!=51){
      for(int j=0;j<t[i];j++){
        cout << char('a'+i);
      }
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class BChocolate {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            int x = in.nextInt();
            int res = 0;
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < d; j++) {
                    if (j % a[i] == 0) res++;
                }
            }

            out.println(res + x);

        }

    }
}



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

using namespace std;

int main(void) {
  int N;
  string s;
  std::cin >> N;
  std::cin >> s;
  int r_num =0;
  int b_num =0;

  for (auto c: s) {
    if (c == 'R') {
      r_num++;
    } else {
      b_num++;
    }
  }
  if (r_num > b_num) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
 
int main() {
    long x,n;
    cin>>x>>n;
 	
  	long ans = x-n;
  	if(ans >= 0){
       cout<<(x-n);
    }else{
       cout<<0;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    long long K; cin >> K;
    vector<long long> A(N); for (auto& a : A) cin >> a;
    long long best = 0;
    for (long long bit = 1LL << 40; bit; bit >>= 1) {
        int cnt = 0;
        for (auto a : A) if (a & bit) cnt++;
        if (cnt <= N / 2) best |= bit;
    }
    long long ans = 0;
    for (auto a : A) ans += a ^ K; // X == K
    for (long long bit = 1LL << 40; bit; bit >>= 1) {
        if (K & bit) {
            long long X = (K & ~(bit - 1) & ~bit) | (best & (bit - 1));
            long long f = 0;
            for (auto a : A) f += a ^ X;
            ans = max(ans, f);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
const int INF = 1e8;

int main(){
  int D,G; cin >> D >> G;
  vector<int> p(D),c(D);
  for(int i=0;i<D;i++){
    cin >> p[i] >> c[i];
  }
  int ans = INF;
  for(int s=0;s<(1<<D);s++){
    int solve = 0,score = 0;
    int partial = -1;
    for(int i=0;i<D;i++){
      if(s&(1<<i)){
        solve += p[i];
        score += 100*(i+1)*p[i] + c[i];
      }else{
        partial = i;
      }
    }  
      int less = G-score;
      if(less > 0){
        int prob_socre = 100*(partial+1);
        if(less > prob_socre*p[partial]) continue;
        solve+=min(p[partial],(less+(prob_socre-1))/prob_socre);
      }
      chmin(ans,solve);
  
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < (int)(x); i++)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m,c; cin >> n >> m >> c;
    vector<ll> b(m);
    rep(i,m) cin >> b[i];
    vvl a(n,vector<ll>(m,0));
    rep(i,n)rep(j,m){
        cin >> a[i][j];
    }

    ll res = 0;
    rep(i,n){
        ll temp = 0;
        rep(j,m)temp += b[j] * a[i][j];
        temp += c;
        if(0 < temp)res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool same(int a,int b){
  if(a*b>=0) return true;
  return false;
}
int max(int a,int b){
  return(a>b)?(a):(b);
}
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int d;
    int s[n];
    int count = 0;
    int ans=-100001;
    for(int i=0;i<n;i++){
      cin >> d;
      if(ans<d) ans = d;
      if(i==0) s[0] = d;
      else if(same(d,s[count])) s[count] += d;
      else{
	count++;
	s[count] = d;
      }     
    }
    //for(int i=0;i<=count;i++) cout << s[i] << endl;
    if(count==0){
      cout << max(s[0],ans) << endl; 
      continue;
    } 
    for(int i=0;i<=count;i++){
      int h = 0;
      if(ans<h) ans = h;
      for(int j=i;j<=count;j++){
	h += s[j];
	if(ans<h) ans = h;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1168
sx,sy,tx,ty = map(int,input().split())
ans = "U"*(ty-sy)+"R"*(tx-sx)+"D"*(ty-sy)+"L"*(tx-sx)
ans += "L"+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D"
ans += "R"+"D"*(ty-sy+1)+"L"*(tx-sx+1)+"U"
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
int main(void) {
  int N;
  scanf("%d",&N);
  int A[N];
  int i,j,k;
  
  for(i=0;i<N;i++) {
    scanf("%d",&A[i]);
  }
  
  int tmp;
  
  for(i=0;i<N;i++) {
    printf("%d",A[i]);
    if(i!=N-1)
      putchar(' ');
  }
  putchar('\n');
  
  for(i=1;i<N;i++) {
    j=i;
    while(j>0 && A[j]<A[j-1]) {
      tmp=A[j];
      A[j]=A[j-1];
      A[j-1]=tmp;
      j--;
    }
    for(k=0;k<N;k++) {
      printf("%d",A[k]);
      if(k!=N-1)
	putchar(' ');
    }
    putchar('\n');
  }
  return 0;
}



Measured memory_bytes: 2036
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>

using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;

int inf=1e9+1000;
const int mod=1e9+7;
ll infi=1e18+100;

//x=10111;
//x<<2 = 1011100 (右シフト),x>>2 = 101 (左シフト)
//(x>>2)&1 = 101 & 001 = 1
//iビット目は、(x>>i) & 1 でわかる(x>>i)%2 でもよい


int x, a,b;



int main(){
	cin>>x>>a>>b;
	if(abs(x-a)>abs(x-b)){
		cout<<"B"<<endl;
	}
	else cout<<"A"<<endl;
	return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include <iosfwd>
#include<limits.h>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <limits>
#include<stdio.h>
#include <queue>
#include <stack>
#include <math.h>
#include<string.h>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include<vector>
#include <chrono>
#include <random>
using namespace std;
using namespace std::chrono;
#define fr(i,j,n)   for(lli i=j;i<(n);++i)
#define bk(i,j,n)   for(lli i=j;i>=n;--i)
#define pb push_back
#define m_p make_pair
#define Fs first
#define Sc second
#define endl "\n"
#define MOD 1000000007
#define present(c,x)    ((c).find(x) != (c).end())
#define count1 __builtin_popcount
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define mem(p,v) memset(p,(lli)v,sizeof p);
#define ub upper_bound
#define lb lower_bound
typedef long long int lli;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<lli> vl;
typedef pair<lli,lli> pl;
inline lli max(lli a,lli b){ return a>b?a:b;}
inline lli min(lli a,lli b){ return a<b?a:b;}
void show(vector<lli> v)
{
    fr(i,0,v.size())
    cout<<v[i]<<" ";
    cout<<endl;
}
void show(vector<int> v)
{
    fr(i,0,v.size())
    cout<<v[i]<<" ";
    cout<<endl;
}
void show(int a[], int arraysize)
{
    for (int i = 0; i < arraysize; ++i)
        cout << a[i] << " ";
    cout<<endl;
}
void show(lli a[], lli arraysize)
{
    for (lli i = 0; i < arraysize; ++i)
        cout << a[i] << " ";
    cout<<endl;
}
void show(unordered_set<int> s)
{
    for (auto it = s.begin(); it != s.end(); it++)
    {
        cout << *it << " ";
    }
    cout<<endl;
}
void show(unordered_map<int,int> mp)
{
    for (auto it = mp.begin(); it != mp.end(); it++)
    {
        cout << it->first << " "<<it->second<<endl;
    }
    cout<<endl;
}


int main()
{
    lli t,n,k,ans;
    t=1;
    while(t)
    {
        lli x;
        cin>>n;
        lli a[n];
        fr(i,0,n)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        lli ans=0;
        fr(i,0,n)
        {
            bool tmp=true;
            if(i<n-1&&a[i+1]==a[i])
                tmp=false;
            if(i>0&&a[i-1]==a[i])
                tmp=false;
            for(int j=1;j<=sqrt(a[i])&&tmp;++j)
            {
                if(a[i]%j==0)
                {
                    int in1=lower_bound(a, a+n, j)-a;
                    int in2=lower_bound(a, a+n, a[i]/j)-a;
                    if((a[in1]==j&&in1!=i)||(a[in2]==a[i]/j&&in2!=i))
                    {
                        tmp=false;
                        break;
                    }
                }
            }
            if(tmp)
                ans++;
        }
        cout<<ans<<endl;
        t--;
    }
    return 0;
}



Measured memory_bytes: 5180
text=input()
n=int(input())
for i in range(n):
    order=input().split()
    a,b=map(int,order[1:3])
    if order[0]=="print":
        print(text[a:b+1])
    elif order[0]=="reverse":
        re_text=text[a:b+1]
        text=text[:a]+re_text[::-1]+text[b+1:]
    else :
        text=text[:a]+order[3]+text[b+1:]
        


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

int main(void){
    int x,i;
    cin >>x;
    int a[x];
    for (i=0; i<x; i++) {
        cin >>a[i];
    }
    for (i=0; i<x; i++) {
        cout<<a[(x-1-i)];
        if ((x-1-i)==0) {
            break;
        }else cout<<" ";
    }
    cout<<endl;
    
}

Measured memory_bytes: 1160
def read_int():
    return int(input())


def read_ints():
    return map(int, input().split(' '))


a, v = read_ints()
b, w = read_ints()
t = read_int()
if w >= v:
    print('NO')
elif abs(a - b) / (v - w) <= t:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 9168
/*Saurav Paul*/
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define endl '\n'
#define loop(i,a,b)           for(ll i=a;i<=b;++i)
#define boost		          ios_base::sync_with_stdio(0);
#define eb                    emplace_back
#define mp                    make_pair
#define clr(x)                x.clear()
#define itoc(c)               ((char)(((int)'0')+c))
#define ctoi(c)               ((int)(((int)c)-'0'))
#define all(p)                p.begin(),p.end()

using ll = long long int ;
using namespace std;
///////////////////////

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef PAUL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define dbg(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#ifdef ONLINE_JUDGE
#define cerr if (false) cerr
#endif

////////////////////////
/*
template<typename T>T set_bit(T N,T pos){return N=N | (1<<pos);}
template<typename T>T reset_bit(T N,T pos){return N= N & ~(1<<pos);}
template<typename T> bool check_bit(T N,T pos){return (bool)(N & (1<<pos));}
template<typename T>void bin_print(T N){bitset<25>bit(N);cerr<<bit.to_string()<<"\n";}
template<typename T> void max_self(T &a, T b){
	a=max(a,b);
}
template <typename T > void min_self(T &a, T b){
	a=min(a,b);
}
template <typename T > void add_self(T &a, T b){
	a+=b;
}
*/
////////////////////////

template<typename T> void ara_read(T &v,ll n){
	ll temp;
	for(ll i=0; i< n; i++){
		scanf("%lld",&temp);
		v.emplace_back(temp);
	}
}
template<typename T> void ara_print(T &v){
	for(ll x : v)
		printf("%lld ",x);
	puts("");
}
////////////////////////
const int INF = 1e9 + 99;
using Pair = pair<int,int >;
using vec = vector<int> ;

int main()
{
	boost ;
	int n;
	cin >> n;
	int mx = 0 , smx =0;
	vec v(n);
	for(int i = 0 ; i < n; i++){
		int temp ; cin >> temp;
		v[i] = temp;
		if(temp > mx)
			smx=mx,mx=temp;
		else{
			if(temp > smx)
				smx = temp;
		}
	}
	
	for(int i = 0 ; i < n; i++){
		//~ cout << v[i] << " " << mx << endl;
		if(v[i]== mx)
			cout << smx << "\n";
		else
			cout << mx << "\n";
	}
	
	
    return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


LL solve(LL n, vector<pair<LL,LL>>& range, bool next_left){
    vector<LL> used(n);
    vector<pair<LL,LL>> left(n);
    vector<pair<LL,LL>> right(n);
    for(LL i = 0; i < n; ++i){
        left[i].first = range[i].second;
        left[i].second = i;
        right[i].first = range[i].first;
        right[i].second = i;
    }
    sort(left.begin(), left.end());
    sort(right.begin(), right.end(), greater<pair<LL,LL>>());
    LL left_cur = 0, right_cur = 0;
    LL ans = 0;
    LL pos = 0;
    while(true){
        if(next_left){
            if(left_cur >= n) break;
            LL cur = left[left_cur++].second;
            if(used[cur]) continue;
            next_left = false;
            used[cur] = 1;
            if(range[cur].second >= pos) continue;
            ans += abs(pos - range[cur].second);
            pos = range[cur].second;
            //cerr << "left:" << pos << ", " << ans << endl;
        }else{
            if(right_cur >= n) break;
            LL cur = right[right_cur++].second;
            if(used[cur]) continue;
            next_left = true;
            used[cur] = 1;
            if(range[cur].first <= pos) continue;
            ans += abs(pos - range[cur].first);
            pos = range[cur].first;
            //cerr << "right:" << pos << ", " << ans << endl;
        }
    }
    ans += abs(pos);
            //cerr << "orign:" << ans << endl;
    return ans;
}

int main(){
    LL n;
    cin >> n;
    vector<pair<LL,LL>> range(n);
    for(LL i = 0; i < n; ++i){
        cin >> range[i].first >> range[i].second;
    }
    LL ans = max<LL>(solve(n, range, true), solve(n, range, false));
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include <utility>
#include<map>
#include<functional>
#include<climits>
#include<regex>
#include<numeric>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
	ll n, k;
	ll an = 0;
	ll  qwe = 0;
	cin >> n >> k;
	while (1) {
		if (k > (1 << qwe))qwe++;
		else break;
	}
	for (int i = 1; i <= n; i++) {
		if (i >= k) {
			an += (1 << qwe);
			continue;
		}
		int memo = 0;
		while (1) {
			if (k > (i << memo))memo++;
			else break;
		}
		an += (1<<(qwe-memo));
	}
	double doub=(double)an/ ((1 << qwe)*n);
	cout << std::fixed;
	cout << setprecision(13) << doub << endl;
}



Measured memory_bytes: 256
def to753(k,d):
    res=0
    for j in range(d):
        res+=(3+2*(k%3))*10**j
        k//=3
    return res

def has753(x):
    f3=f5=f7=False
    while x>0:
        f3=f3 or x%10==3
        f5=f5 or x%10==5
        f7=f7 or x%10==7
        x//=10
    return f3 and f5 and f7

N=int(input())

ans=0

fEND=False

for d in range(3,10):
    if fEND:break
    for k in range(3**d):
        x=to753(k,d)
        if x>N:fEND=True;break
        if has753(x):
            ans+=1

print(ans)

Measured memory_bytes: 46300
#include<bits/stdc++.h>
using namespace std;
 
int ans(int n, int a, int b, int k){
    return a + b + n*pow(2,k);
}

int main(){

    int a,b,c,k;
    cin >> a >> b >> c >> k;

    if(a > b && a > c){
        cout << ans(a,b,c,k) << endl;
    }else if(b > a && b > c){
        cout << ans(b,a,c,k) << endl;
    }else{
        cout << ans(c,a,b,k) << endl;
    }

}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	for q := ReadInt(); q > 0; q-- {
		x, y := ReadString(), ReadString()
		fmt.Println(LCS(x, y))
	}
}

func LCS(x, y string) int {
	dp := make([][]int, len(x)+1)
	for i := 0; i < len(x)+1; i++ {
		dp[i] = make([]int, len(y)+1)
	}
	for i := 0; i < len(x); i++ {
		for j := 0; j < len(y); j++ {
			dp[i+1][j+1] = Max(dp[i+1][j], dp[i][j+1])
			if x[i] == y[j] {
				dp[i+1][j+1] = Max(dp[i+1][j+1], dp[i][j]+1)
			}
		}
	}
	return dp[len(x)][len(y)]
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}



Measured memory_bytes: 18984
#include <iostream>
#include <cstdio>

using namespace std;

int n,p;
int a[101];
long long f[101][2];

int main(){
	scanf("%d%d",&n,&p);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	f[0][0]=1,f[0][1]=0;
	for (int i=1;i<=n;i++)
		if (a[i]%2==1){
			f[i][1]=f[i-1][1]+f[i-1][0];
			f[i][0]=f[i-1][0]+f[i-1][1];
		}
		else{
			f[i][1]=f[i-1][1]*2;
			f[i][0]=f[i-1][0]*2;
		}
	cout<<f[n][p]<<endl;
	return 0;
}

Measured memory_bytes: 256
#! /usr/bin/python
# -*- coding: utf-8 -*-

s = raw_input()
while s != '.':
    b = []
    for i in range(len(s)+1):
        if i == len(s):
            if len(b) == 0:
                print "yes"
                break
            else:
                print "no"
                break

        if s[i]=='(' or s[i]=='[':
            b.append(s[i])
        if s[i]==')' or s[i]==']':
            if len(b) == 0:
                print "no"
                break
            elif b[-1]=='(' and s[i]==')':
                b.pop()
            elif b[-1]=='[' and s[i]==']':
                b.pop()
            else:
                print "no"
                break

    s = raw_input()

Measured memory_bytes: 4228
/*
 * Author : Sadi
 * Sat 27/06/2020
 * 19:14:37.80
 */
#include <bits/stdc++.h>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    int count = 0;
    for(int i = 1; i <= n; i += 2) {
        vector<int> divisors;
        int k = 1;
        while(k * k <= i) {
            if(i % k == 0) {
                if(k == i / k) {
                    divisors.push_back(k);
                }
                else {
                    divisors.push_back(k);
                    divisors.push_back(i / k);
                }
            }
            k++;
        }
        if(divisors.size() == 8) {
            count++;
        }
        divisors.clear();
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3636
SC=[]
n,m=map(int,input().split())
if n==1:
      r=range(0,10)
elif n==2:
      r=range(10,100)
else:
      r=range(100,1000)
for _ in range(m):
  s,c=map(int,input().split())
  s-=1
  SC.append((s,c))
for i in r:
      i=str(i)
      for s,c in SC:
            if i[s]!=str(c):
                break
      else:
            print(int(i))
            exit()

print(-1)


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    if (a > m) continue;
    jobs[a-1].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  rep(i,m) {
    for (int b : jobs[i]) { //範囲for文。配列の要素に対して繰り返しを適用
      q.push(b);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5632
#include <stdio.h>
int main(void){
    int a;
    scanf("%d", &a);
    if(a == 25){
        printf("Christmas");
    }else if(a == 24){
        printf("Christmas Eve");
    }else if(a == 23){
        printf("Christmas Eve Eve");
    }else if(a == 22){
        printf("Christmas Eve Eve Eve");
    }

}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#include <string>
#include <sstream>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define clr(a) memset(a, 0, sizeof(a))
#define set(a) memset(a, -1, sizeof(a))
#define pb push_back
#define sz(a) ((ll)a.size())
#define all(a) a.begin(), a.end()
#define mp make_pair
#define rep(i, a, y) for (ll i = a; i <= y; i++)
#define rep2(i, b) for (int i = 0; i < b; i++)
#define repl(i, a, b) for (ll i = a; i <= b; i++)
#define ppi pair<int, int>
#define scl(x) scanf("%d", &x)
#define pcl(x) printf("%d", x)
#define FastRead                  \
	ios_base::sync_with_stdio(0); \
	cin.tie(0)
/*
 
     ██╗██╗   ██╗██╗  ██╗ █████╗ ███╗   ██╗
     ██║██║   ██║██║  ██║██╔══██╗████╗  ██║
     ██║██║   ██║███████║███████║██╔██╗ ██║
██   ██║██║   ██║██╔══██║██╔══██║██║╚██╗██║
╚█████╔╝╚██████╔╝██║  ██║██║  ██║██║ ╚████║
 ╚════╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝
 
*/
bool abc(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
	return a.second>b.second && a.first<b.first;
	//else 0;
}
int main()
{
	int k,s,cnt=0;
	cin>>k>>s;
	for(int i=0;i<=k;i++)
	{
		for(int j=0;j<=k;j++)
		{
			if((s-i-j)>=0 &&(s-i-j)<=k) cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	vector<int> ord(N);
	iota(ord.begin(), ord.end(), 0);
	sort(ord.begin(), ord.end(), [&](int i, int j) -> bool {
		return A[i] < A[j];
	});
	vector<int> inv(N);
	for (int i = 0; i < N; i++) {
		inv[ord[i]] = i;
	}

	for (int i = 0; i < N; i++) {
		if (inv[i] < N/2) {
			cout << A[ord[N/2]] << '\n';
		} else {
			cout << A[ord[N/2-1]] << '\n';
		}
	}

	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int lenS = S.size();
  int cal = 1;
  for (int i=0; i<lenS-1; i++) cal *= 2;
  long long ans = 0;
  for (int i=0; i<cal; i++){
    long long tmp = S[0] - '0';
    int check = i;
    for (int j=1; j<lenS; j++){
      if (check&1){
        ans += tmp;
        tmp = S[j] - '0';
      } else {
        tmp = tmp*10 + S[j] - '0';
      }
      check >>= 1;
    }
    ans += tmp;
  }
  cout << ans << endl;
}


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

int main(int argc, char* argv[])
{
  int a, b, k;

  std::cin >> a >> b >> k;

  int x = 0;
  for (int i = a; i < a+k && i < b; i++) {
    std::cout << i << std::endl;
    x = i;
  }

  for (int i = b-k+1; i <= b; i++) {
    if (i > x) {
      std::cout << i << std::endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
void solve()
{
    ll x;
    cin>>x;
    int ans=0;
    ll now=100;
    while(now<x){
        ans++;
        now=now+now/100;
    }
    printf("%d\n",ans);
}
int main()
{
	///int _;cin>>_;while(_--)
	solve();
}


Measured memory_bytes: 3716
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long INF = 1L<<59;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto LRA = M.iota.map!(_ => readln.split.map!(to!int).array).array;
    LRA.sort();

    auto st = new LazySegmentTree!(long, long, max, (a,b)=>a+b, (a,b)=>a+b, (a,b)=>a, -INF, 0L)(N+1);
    st.table[] = 0L;
    auto pq = new BinaryHeap!(Array!(Tuple!(int, int, long)), "a[1] > b[1]")();

    for (int i = 1, p = 0; i <= N; ++i) {
        while (p < M && i >= LRA[p][0]) {
            pq.insert(tuple(LRA[p][0], LRA[p][1], LRA[p][2].to!long));
            st.update(0, LRA[p][0]-1, LRA[p][2].to!long);
            ++p;
        }

        auto v = st.query(0, i-1);
        st.update(i, i, v);

        while (!pq.empty && pq.front[1] <= i) {
            st.update(0, pq.front[0]-1, -pq.front[2].to!long);
            pq.removeFront;
        }
    }

    st.query(0, N).writeln;
}



class LazySegmentTree(T, L, alias opTT, alias opTL, alias opLL, alias opPrd, T eT, L eL) {
    T[] table;
    L[] lazy_;
    int n;
    int size;

    this(int n) {
        this.n = n;
        size = 1;
        while (size <= n) size <<= 1;
        size <<= 1;
        table = new T[](size);
        lazy_ = new T[](size);
        table[] = eT;
        lazy_[] = eL;
    }

    void push(int i, int a, int b) {
        if (lazy_[i] == eL) return;
        table[i] = opTL(table[i], opPrd(lazy_[i], b - a + 1));
        if (i * 2 + 1 < size) {
            lazy_[i*2] = opLL(lazy_[i*2], lazy_[i]);
            lazy_[i*2+1] = opLL(lazy_[i*2+1], lazy_[i]);
        }
        lazy_[i] = eL;
    }

    T query(int l, int r) {
        if (l > r) return eT;
        return query(l, r, 1, 0, n-1);
    }

    T query(int l, int r, int i, int a, int b) {
        if (b < l || r < a) return eT;
        push(i, a, b);
        if (l <= a && b <= r) {
            return table[i];
        } else {
            return opTT(query(l, r, i*2, a, (a+b)/2), query(l, r, i*2+1, (a+b)/2+1, b));
        }
    }

    void update(int l, int r, L val) {
        if (l > r) return;
        update(l, r, 1, 0, n-1, val);
    }

    void update(int l, int r, int i, int a, int b, L val) {
        if (b < l || r < a) {
            push(i, a, b);
        } else if (l <= a && b <= r) {
            lazy_[i] = opLL(lazy_[i], val);
            push(i, a, b);
        } else {
            push(i, a, b);
            update(l, r, i*2, a, (a+b)/2, val);
            update(l, r, i*2+1, (a+b)/2+1, b, val);
            table[i] = opTT(table[i*2], table[i*2+1]);
        }
    }
}


Measured memory_bytes: 25404
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    int n,l,r,ans = 0;
    cin >> n;
    for(int i = 0;i < n;i++)
    {
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N;
  cin>>N; 
 vector<int> v(N);
  for(int i=0;i<N;++i){
    cin>>v[i];
  }
int c = 0;
 for(int i = 1; i < N-1;i++){
   if((v.at(i-1) > v.at(i) && v.at(i) > v.at(i+1)) || 
      (v.at(i-1) < v.at(i) && v.at(i) < v.at(i+1))){
     c++;
}
 }
  cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> Pii;
const int inf = (1<<28) +11555;
int main(){
    lli n,m;
    cin >> n >> m;
    vector<lli> avec(n);
    vector<lli> acum_avec(n);
    // sort(vc.begin(),vc.end())
    lli tmp = 0;
    lli uke;
    rep(i,n){
        cin >> uke;
        avec.at(i) = uke;
    }
    sort(avec.begin(),avec.end());
    rep(i,n){
        acum_avec.at(i) = tmp + avec.at(i);
        tmp += avec.at(i);
    }
    lli ok = -1;
    lli ng = 2*avec.at(n-1) + 3;
    lli mid;
    lli sum_x;
    lli outrange;
    while (ng - ok > 1) {
        mid = (ok + ng)/2;
        sum_x = 0;
        rep(i,n){
            sum_x +=  n -  (lower_bound(avec.begin(),avec.end(),mid - avec.at(i)) - avec.begin());
        }
        if(sum_x >= m){
            ok = mid;
            outrange = sum_x-m;
        }
        else ng = mid;
    }
    lli ans = 0;
      rep(i,n){
          sum_x =  n -  (lower_bound(avec.begin(),avec.end(),ok - avec.at(i)) - avec.begin());
          if (sum_x != (lli) n) ans += avec.at(i) * sum_x + acum_avec.at(n-1) -  acum_avec.at(n - sum_x -1);
          else ans += avec.at(i) * sum_x + acum_avec.at(n-1);
      }

    ans -=  outrange * ok;
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <climits>
#include <string>
#define input std::cin

using vector = std::vector<int>;
using lint = long long int;
using string = std::string;

int main() {
  string s, t;
  input >> s >> t;
  int min_change = INT_MAX;
  for (int i=0; i<=s.size()-t.size(); i++) {
	int changes = 0;
	for (int j=0; j<t.size(); j++) {
	  if (s[i+j] != t[j])
		changes ++;
	}
	if (changes < min_change)
	  min_change = changes;
  }
  std::cout << min_change << std::endl;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }


using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    vector<ll> a(N+1);
    rep(i, N) cin >> a[i+1];

    vector<ll>bits;
    rep(i, N) a[i+1] += a[i];
    rep(i, N) {
        for (int j = i; j < N; ++j) {
            ll sum = a[j+1] - a[i];
            bits.push_back(sum);
        }
    }

    sort(bits.rbegin(), bits.rend());

    vector<ll> now = bits;
    for (ll b = 63; b >= 0; --b) {
        vector<ll> next;
        for (auto i : now) {
            if (i & (1LL << b)) next.push_back(i);
        }

        if (next.size() >= K) now = next;
    }

    ll ans = now[0];
    rep(i, K) ans &= now[i];
    cout << ans << endl;


}

Measured memory_bytes: 10096
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007

long long int fac(int n)
{
    long long int tot = 1;
    for(int i=1;i<=n;i++)
    {
        tot = ((tot%M)*(i%M))%M;
    }
    return tot;
}

int main() {
    int n,m;
    cin>>n>>m;
    long long int ans = 0;
    if(abs(n-m) > 1)
    {
        cout<<"0\n";
        return 0;
    }
    ans = (fac(n)%M*fac(m)%M)%M;
    if(n == m)
    {
        ans = ((ans%M)*2)%M;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void) {
	int n, a;
	int min = 9999;
	int max = 0;
	scanf("%d", &n);

	for (int i = 0; i < n; ++i) {
		scanf("%d", &a);
		max = fmax(max, a);
		min = fmin(min, a);
	}

	printf("%d", max - min);


	return 0;
}

Measured memory_bytes: 128
n=int(input())
lx=[]
ly=[]
for i in range(n):
    x,y=[int(j) for j in input().split()]
    lx.append((i,x,y))
    ly.append((i,x,y))
from operator import itemgetter
lx.sort(key=itemgetter(1))
ly.sort(key=itemgetter(2))
# 最小全域木
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import minimum_spanning_tree
edge=set()
for i in range(n-1):
    i1,x1,y1=lx[i]
    i2,x2,y2=lx[i+1]
    d=min(abs(x1-x2),abs(y1-y2))
    edge.add((i1,i2,d))
for i in range(n-1):
    i1,x1,y1=ly[i]
    i2,x2,y2=ly[i+1]
    d=min(abs(x1-x2),abs(y1-y2))
    edge.add((i1,i2,d))
row,col,value = zip(*edge)
value = np.array(value,dtype=int)
graph = csr_matrix((value,(row,col)),shape=(n,n))

tree = minimum_spanning_tree(graph,overwrite = True).astype(int)
print(tree.sum())


Measured memory_bytes: 96976
#include<bits/stdc++.h>
#define ll long long int
#define ss second
#define ff first
#define pb push_back
#define all(v) v.begin(),v.end()
#define unik(v)  v.erase(unique(v.begin(),v.end()),v.end())
using namespace std;
typedef pair<int, int> pii;
const ll mod = 998244353;
const int sz = 1000 + 3, inf = 1e9 + 10;
int a[sz];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	ll n, k;
	cin >> n >> k;
	ll r = n % k;
	cout << min(r, abs(r - k)) << '\n';


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cstdlib>
    using namespace std;
    int n,m,a[100005],cnt[100005];
    int main(){
    	cin>>n;
    	int ans=0;
    	for(register int i=1;i<=n;i++)cin>>m,cnt[m]++,cnt[m+1]++,cnt[m-1]++;
    	for(register int i=0;i<=100000;++i)ans=max(ans,cnt[i]);
    	cout<<ans<<endl;
    	return 0;
    }

Measured memory_bytes: 640