akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b,ll c){if(a==b)out(c);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
ll solve(string s){
    int n=s.size();
    vvi dp0(n,vi(10)),dp1(n,vi(10));
    REP(i,1,s[0]-'0')dp1[0][i]=1;
    dp0[0][s[0]-'0']=1;
    rep(i,n-1){
        rep(j,10){
            rep(k,10){
                if(abs(j-k)>1)continue;
                dp1[i+1][k]+=dp1[i][j];
                if(k==s[i+1]-'0')dp0[i+1][k]+=dp0[i][j];
                if(k<s[i+1]-'0')dp1[i+1][k]+=dp0[i][j];
            }
        }
        REP(j,1,10)dp1[i+1][j]++;
    }
    ll res=0;
    rep(i,10)res+=dp1[n-1][i]+dp0[n-1][i];
    //outvv(dp1);
    //outvv(dp0);
    return res;
}
int main(){
    ll n;cin>>n;
    ll ok=3234566667,ng=0;
    //out(solve("23"));
    while(ok-ng>1){
        ll md=(ok+ng)/2;
        ll k=solve(to_string(md));
        if(k>=n)ok=md;
        else ng=md;
    }
    out(ok);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>

using namespace std;

typedef long long ll;

string beautify(string str) {
	string ret = "";
	for (int i = 0; i < str.size(); ++i) {
		char c = str[i];
		if ('a' <= c && c <= 'z') ret += c;
		else if ('A' <= c && c <= 'Z') ret += (char)(c-'A'+'a');
	}
	return ret;
}

int main() {
	double a, b, c; cin >> a >> b >> c;
	c = c * M_PI / 180;
	printf("%.10f %.10f %.10f\n", a * b * sin(c) / 2, a+b+sqrt(a*a + b*b - 2*a*b*cos(c)), b * sin(c));
}

Measured memory_bytes: 1264
n = int(input())
s = []
for i in range(n):
    s.append(int(input()))
total = sum(s)
if total % 10 == 0:
    s.sort()
    for i in s:
        if i % 10 != 0:
            total -= i
            break
if total % 10 == 0:
    total = 0
print(total)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll n;
    cin >> n;
    vec a(n);
    loop(i, n) cin >> a[i];
    ll x = 0;
    loop(i, n) x ^= a[i];
    vec ans(n);
    loop(i, n) ans[i] = x ^ a[i];
    loop(i, n)
    {
        cout << ans[i];
        if (i != n - 1)
            cout << " ";
        else
            putout("");
    }
    return 0;
}


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

int main()
{
	long long int i=1, j, count=0, n;
	cin >> n;
	j=(n-i)/i;
	while(i<j)
	{
		//cout << i << " " << j << endl;
		if((n-i)%j==0)
			count+=j;
		i+=1;
		j=(n-i)/i;
	}
	cout << count << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  double t, x;
  cin >> t >> x;
  cout << fixed << setprecision(12) << t / x << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;
using Graph = vector<vector<int>>;
int dist[2001][2001];

int main(){
  lll ii,jj,kk;
  vector<int> ret;

  int n,x,y;
  
  cin >> n >> x >> y;

  Graph g(n);

  for(ii=0;ii<n-1;ii++){

    g[ii].push_back(ii+1);
    g[ii+1].push_back(ii);
    
  }

  g[x-1].push_back(y-1);
  g[y-1].push_back(x-1);
  
  vector<int> todo;
  vector<bool> seen(n);


  int v;
  //cout << "start" << endl;

  memset(dist,0,sizeof(dist));

  for(ii=0;ii<n;ii++){
    seen.assign(n,false);
    seen[ii] = true;
    todo.push_back(ii);
    dist[ii][ii] = 0;

    while(!todo.empty()){
      v = todo[0];

      todo.erase(todo.begin());
      //cout << "v:" << v << endl;
      
      for(auto w : g[v]){
        if(seen[w] == true){continue;}

        seen[w] = true;
        todo.push_back(w);
        dist[ii][w] = dist[ii][v] + 1;
      }

    }
  }

  lll ans[2001];
  memset(ans,0,sizeof(ans));
  
  for(ii=0;ii<n;ii++){
    for(jj=ii+1;jj<n;jj++){
      //cout << dist[ii][jj] << " ";
      ans[dist[ii][jj]]++;
    }
    //cout << endl;
  }

  for(ii=1;ii<n;ii++){
    cout << ans[ii] << endl;
  }
  return 0;
}


Measured memory_bytes: 19332
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
int main() {
	double a, b, S, L, h, C, c;
	cin >> a >> b >> C;
	C = C*acos(-1) / 180.0;
	S = a*b*sin(C)*0.5;
	h = b*sin(C);
	c = pow(h, 2) + pow(a - b*cos(C), 2);
	c = pow(c, 0.5);
	L = a + b + c;
	printf("%.6lf\n", S);
	printf("%.6lf\n", L);
	printf("%.6lf\n", h);
}

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

int main() {
    
    long long int n,left=0,right,count=0;
    cin>>n;
    string s;
    char temp;
    cin>>s;
    right=n-1;
    while(left<=right)
    {
        while(left<n && s[left]=='R') 
		left++;
        while(right>=0 && s[right]=='W') 
		right--;
        if(left<right){
        	temp=s[left];
        	s[left]=s[right];
        	s[right]=temp;
			count++;
//			cout<<s<<endl;
		}
    }
    cout<<count;
	return 0;
}


Measured memory_bytes: 3752
using System;
using System.Collections.Generic;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputFirstLine = Console.In.ReadLine();
            var count = int.Parse(inputFirstLine);

            var inputLine = Console.In.ReadLine();
            var inputs = inputLine.Split(new char[] { ' ', '\t', '　' });
            if (inputs.Length != count)
            {
                return;
            }

            int min = int.MaxValue;
            int max = int.MinValue;
            Int64 sum = 0;
            foreach (var str in inputs)
            {
                var i = int.Parse(str);
                min = Math.Min(min, i);
                max = Math.Max(max, i);
                sum += i;
            }

            Console.WriteLine("{0} {1} {2}", min, max, sum);
        }
    }
}


Measured memory_bytes: 17984
open System
open System.Diagnostics


let words = [|"dream"; "dreamer"; "erase"; "eraser"|]
let s = stdin.ReadLine()
let len = s.Length

let inline subStrEq (m:int) (n:int) (ss:string) =
  let e = m+n
  if e > len
  then false
  else
    seq {m..(e-1)}
    |> Seq.map (fun i -> s.[i])
    |> Seq.compareWith Operators.compare ss
    |> (=) 0

let inline startsWith (pos:int) (pre:string) =
  let l = pre.Length
  if subStrEq pos l pre
  then Some(l)
  else None

let rec judge (pos:int) =
  if pos = len then
    true
  else
    words
    |> Seq.choose (startsWith pos)
    |> Seq.map ((+) pos)
    |> Seq.exists judge

if judge 0 then "YES" else "NO"
|> printfn "%s"

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

using namespace std;

int main(int argc, char *argv[]) {
	int A, B, C;
	cin >> A >> B >> C;

	vector<bool> remainder(B);
	for (int i = 1; i < B; i++) {
		remainder[(A * i) % B] = true;
	}

	if (remainder[C]) printf("YES\n");
	else printf("NO\n");
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int partition(int *A,int p,int r){
  int x=A[r];
  int i=p-1;
  for(int j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1;
}
int main(){
  int n;
  int A[100000];
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> A[i];
  }
  int re;
  re=partition(A,0,n-1);
  for(int i=0;i<n;i++){
    if(i)cout << " ";
    if(i==re)cout << '[' << A[i] << ']' ;
    else cout << A[i];
  }
  cout << endl;
  return 0;
}

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

double bmi(double w, double m){
  return w / m / m;
}

int main(){
  int n;

  while(cin >> n, n){
    int ans = -1;
    double minDiff = 999999999;

    for(int i = 0; i < n; i++){
      int num, h, w;
      cin >> num >> h >> w;

      double b = fabs(bmi(w, h / 100.0) - 22.0);

      if(minDiff > b || minDiff == b && ans > num){
        ans = num;
        minDiff = b;
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
#include	<stdio.h>

int		main(void)
{
	double d, t, s;
	double time;

	scanf("%lf %lf %lf", &d, &t, &s);
	time = d / s;

	if (time <= t) {
		printf("Yes");
	}
	else {
		printf("No");
	}

	return 0;
}

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

class Main {

    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        String[] s = new String[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                s[i] = sc.next();
        }
        solve(N, s);
    }

    static void solve(long N, String[] s){
        HashMap<String, Long> hm = new HashMap<>();
        for (String si : s) {
            char[] ca = si.toCharArray();
            Arrays.sort(ca);
            Long val = hm.get(new String(ca));
            if(val == null) {
                val = (long)1;
            } else {
                val++;
            }
            val = hm.put(new String(ca), val);
        }

        long ans = 0;
        for (Map.Entry<String, Long> entry: hm.entrySet()) {
            long v = entry.getValue();
            ans += v * (v-1) / 2;
        }
        System.out.println(ans);

        



    }
}


Measured memory_bytes: 60804
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <string>
#include <set>


using namespace std;

long long dp[1024];
long long vals[1024];
int main() {
	int N; cin >> N;
	for (int i = 0; i < N; i++) cin >> vals[i];
	dp[N - 1] = vals[N - 1];
	for (int i = N - 2; i >= 0; i--) {
		for (int j = i + 2; j < N; j += 2) dp[i] = max(dp[i], dp[j]);
		dp[i] += vals[i];
	}
	int st = max_element(dp, dp + N) - dp;
	cout << dp[st] << endl;
	vector<int> nos;
	while (true) {
		nos.push_back(st);
		bool found = false;
		for (int j = st + 2; j < N; j+=2) if (dp[st] == dp[j] + vals[st]) {
			st = j;
			found = true;
			break;
		}
		if (!found) break;
	}
	// Remove all starting elements
	vector<int> pos;
	int rem = N;
	for (int i = 0; i < nos[0]; i++,rem--) pos.push_back(0);
	for (int i = N - 1; i > nos.back(); i--, rem--) pos.push_back(rem - 1);
	for (int i = 1; i < nos.size(); i++) {
		int st = nos[i - 1], ed = nos[i];
		int cnt = (ed - st) >> 1;
		for (int j = 0; j < cnt; j++) pos.push_back(cnt - j);
	}
	cout << pos.size() << endl;
	for (auto x : pos) cout << x+1 << endl;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int, input().split()))
L=min(A)
R=max(A)
MIN=1000000000000000
for i in range(L, R+1):
    length=0
    for j in range(N):
        length+=(A[j]-i)**2
    if length<=MIN:
        MIN=length

print(MIN)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int par[100'000];

void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
    }
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    par[x] = y;
}

int main() {
    int N, M;
    cin >> N >> M;
    init(N);

    for (int m = 0; m < M; m++) {
        int x, y, z;
        cin >> x >> y >> z;

        unite(x - 1, y - 1);
    }

    set<int> res;
    for (int n = 0; n < N; n++) {
        res.insert(find(n));
    }

    cout << res.size() << endl;

    return 0;
}


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

int w[60], r[60], b[60];

int main()
{
  int n, m;
  cin >> n >> m;
  string flag[n + 1];
  
  for (int i = 1; i <= n; i++) {
    cin >> flag[i];
    for (int j = 0; j < m; j++){
      char c = flag[i][j];
      if (c == 'W') w[i]++;
      else if (c == 'R') r[i]++;
      else if (c == 'B') b[i]++;
    }
  }
  long res = 100000000, ct;
  for (int i = 1; i <= n - 2; i++){
    for (int j = 1; i + j <= n - 1; j++){
      ct = 0;
      for (int k = 0; k < i; k++) ct += m - w[k + 1];
      for (int k = 0; k < j; k++) ct += m - b[i + k + 1];
      for (int k = 0; k < n - i - j; k++) ct += m - r[i + j + k + 1];
      res = min(res, ct);
    }
  }

  cout << res << '\n';
}

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

int main()
{
    int64_t N, M;
    std::cin >> N >> M;

    std::vector<int64_t> A;
    for (int64_t i = 0; i < N; i++)
    {
        int64_t a;
        std::cin >> a;
        A.push_back(a);
    }
    std::sort(A.begin(), A.end());

    std::vector<std::pair<int64_t, int64_t>> BC;
    for (int64_t i = 0; i < M; i++)
    {
        int64_t B, C;
        std::cin >> B >> C;
        BC.push_back(std::make_pair(C, B));
    }
    // 大きな C を先に処理すれば、小さな C でちまちまと書き換えずに済む
    std::sort(BC.begin(), BC.end());
    std::reverse(BC.begin(), BC.end());

    auto iterBC = BC.begin();
    for (auto iterA = A.begin(); iterA != A.end(); iterA++)
    {
        if (iterBC == BC.end())
            break;

        auto &currentBC = *iterBC;
        auto overwriteNumber = currentBC.first;
        auto &remain = currentBC.second;
        auto &currentCard = *iterA;

        // 処理カード値が上書き値よりも大きければ、もう書き換える必要はない
        if (currentCard > overwriteNumber)
            break;

        currentCard = overwriteNumber;
        remain--;

        if (remain <= 0)
            iterBC++;
    }

    int64_t maxSum = 0;
    for (auto iter = A.begin(); iter != A.end(); iter++)
    {
        maxSum += *iter;
    }
    std::cout << maxSum << std::endl;
    return 0;
}


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

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


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

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


Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys


def solve(N: int, P: "List[int]"):
    c=1
    min_n = P[0]
    for i in range(1,N):
        if P[i]<min_n:
            min_n=P[i]
            c+=1
    print(c)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, P)

if __name__ == '__main__':
    main()


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

using namespace std;

int main () {
    
    int n;
    cin >> n;
    vector<vector<int>> points(n, vector<int>(3));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> points[i][j];
        }
    }
    vector<vector<int>> dp(n, vector<int>(3, INT_MIN));
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            if (i == 0) {
                dp[i][j] = points[i][j];
            } else {
                for (int k = 0; k < 3; ++k) {
                    if (k == j) continue;
                    dp[i][j] = max(dp[i][j], points[i][j]+dp[i-1][k]);
                }
            }
        }
    }
    for (int i = 0; i < 3; ++i) {
        ans = max(ans, dp[n-1][i]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

void print(string s, int a, int b) {
    for(int i = a; i <= b; i++) {
        cout << s[i];
    }
    cout << endl;
}

string reverse(string s, int a, int b) {
    for(int i = 0; i < (b - a + 1) / 2; i++){
        char tmp = s[a + i];
        s[a + i] = s[b - i];
        s[b - i] = tmp;
    }
    return s;
}

string replace(string s, int a, int b, string p) {
    for (int i = 0; i < p.length(); i++) {
        s[a + i] = p[i];
    }
    return s;
}

int main() {
    string s, query;
    cin >> s;
    int a, b, q;
    cin >> q;
    for (int i = 0; i < q; i++){
        cin >> query;
        if(query == "print") {
            cin >> a >> b;
            print(s, a, b);
        } else if (query == "reverse") {
            cin >> a >> b;
            s = reverse(s, a, b);
        } else if (query == "replace") {
            string p;
            cin >> a >> b >> p;
            s = replace(s, a, b, p);
        }
    }
    
    return 0;
}


Measured memory_bytes: 3172
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pi 3.14159265358979
int main() {
	int n;
	cin >> n;
	char a;
	string s, sd;
	int ans = 0;
	int r = 0, w = 0;
	rep(i, n) {
		cin >> a;
		if (a == 'W')w++;
		else r++;
		s += a;
	}
	rep(i, r) {
		sd += "R";
	}
	rep(i, w) {
		sd += "W";
	}
	rep(i, n) {
		if (s.at(i) != sd.at(i))ans++;
	}
	if (ans % 2 == 0)cout << ans / 2 << endl;
	else cout << ans / 2 + 1 << endl;
	return 0;
}

Measured memory_bytes: 3900
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=2e5+5;
int f[maxn],sz[maxn];
int find(int a)
{
    return f[a]==a?a:f[a]=find(f[a]);
}
void merge(int u,int v)
{
    int u_=find(u),v_=find(v);
    if(u_!=v_)
    {
        if(sz[u_]>sz[v_])
            swap(u_,v_);
        f[u_]=v_;
        sz[v_]+=sz[u_];
    }
    return;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        f[i]=i;
        sz[i]=1;
    }
    for(int i=1;i<=m;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        merge(u,v);
    }
    int ans=1;
    for(int i=1;i<=n;i++)
        ans=max(ans,sz[find(i)]);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3292
import math
from collections import defaultdict
ml=lambda:map(float,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())

"""========main code==============="""

s=ip()
ans=0
for i in range(len(s)//2):
    if(s[i]!=s[len(s)-1-i]):
        ans+=1
print(ans)        

Measured memory_bytes: 38384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		String[] strArray = new String[2];
		int a, b;

		while(true) {
	        strArray = br.readLine().split(" ");
	        a = Integer.parseInt(strArray[0]);
	        b = Integer.parseInt(strArray[1]);

	        if(a == 0 && b == 0) {
	        	break;
	        }

	        for(int i=0; i<a; i++) {
	        	for(int j=0; j<b; j++) {

	        		if(i == 0 || i == a-1) {
		        		sb.append("#");
	        		} else if(j == 0 || j == b-1) {
		        		sb.append("#");
	        		} else {
		        		sb.append(".");
	        		}
	        	}
	        	sb.append("\n");
	        }
	        sb.append("\n");
		}

        System.out.print(sb);
	}
}

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


int main()
{
	int N = 0, K = 0, A = 1;
	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		
		if (A * 2 > A + K) {
			A += K;
		}
		else
			A *= 2;
	}

	cout << A << endl;

}


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

int main() {
  string s; cin >> s;
  int ans = 0;
  for(int i = 0 ; i < s.size(); ++i){
    if(s.at(i) != s.at(s.size()-1-i)) ++ans;
  }
  cout << ans/2 << endl;;
  }
  


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << max({a + a - 1, b + b - 1, a + b});
}


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

int main() {
    int N;
    cin >> N;

    
    
   
    for (int n = 1; n <= N; n++)
    {
        int xyz_sum = 3;
        int x = 1;
        int y = 1;
        int z = xyz_sum - x - y;
        int ans = 0;
        bool ng = false;

        while (!ng) {
            //cout << x << "_" << y << "_" << z << endl;
            int p = x*x + y*y + z*z + x*y + y*z + x*z;
            if (p == n) {
                if (x != y && y != z && z != x) ans += 6;
                else if (x == y && y == z && z == x) ans += 1;
                else if (x == y || y == z || z == x) ans += 3; 
            }

            if (z - y >= 2) {
                y++;
                z--;
            }
            else{
                x++;
                y = x;
                z = xyz_sum - x - y;
                if (x > y || y > z) {
                    if (n < p) ng = true;
                    else {
                        xyz_sum++;
                        x = 1;
                        y = 1;
                        z = xyz_sum - x - y;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
tmp = input()
tmp_s = [int(x.strip()) for x in tmp.split(' ')]
N = tmp_s[0] #N    
K = tmp_s[1] #K
tmp = input()
tmp_s = [int(x.strip()) for x in tmp.split(' ')]
count = 0
for i in range(N):
    if tmp_s[i] >= K:
        count += 1
print(count)

Measured memory_bytes: 12288
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;

int main()
{
    int a,b,c,k;
    scanf("%d%d%d",&a,&b,&c);
    scanf("%d",&k);
    if(a>=b&&a>=c)
    {
        a=b+c+pow(2,k)*a;
        printf("%d\n",a);
        return 0;
    }
    if(b>=a&&b>=c)
    {
        b=a+c+pow(2,k)*b;
        printf("%d\n",b);
        return 0;
    }
    if(c>=b&&c>=a)
    {
        c=b+a+pow(2,k)*c;
        printf("%d\n",c);
    return 0;
    }

}


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

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

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

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

int main(){
    bool flag=false;
    ll ans=0,lb=LINF;

    int n;
    cin >>n;
    vector<pair<int,pii>> ra(n);

    rep(i,n){
        int x,l;
        cin>>x>>l;

        ra[i]={x+l,{x,l}};
        chmin(lb,x+l);
    }

    sort(all(ra));

    ll t=(-1)*LINF;
    rep(i,n){
        int x=ra[i].se.fi,l=ra[i].se.se;
        int st=x-l;
        if(t <= st){
            ++ans;
            t = x+l; 
        }
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<ans<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
#define N 200000

void swap(int *x, int *y)
{
	int t;
	t=*x;
	*x=*y;
	*y=t;
 } 
 
 int main()
 {
 	int i,j,k,n,a[N];
 	scanf("%d",&n);
 	for(i=0;i<n;i++)
 	scanf("%d",&a[i]);
 	int min;
 	for(i=0;i<=n-1;i++)
 	{ 
 		min=i; 
 		for(j=i;j<=n-1;j++)
 		{
 			if(a[j]<a[min])
 				min=j;
		 }
		 swap(&a[i], &a[min]);
		 if(i!=min)
		 k++;
	} 
 	for(i=0;i<n;i++)
	{
		if(i>0)printf(" ");
		printf("%d",a[i]);
	}
	printf("\n");
	printf("%d\n",k);
 }


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
int main()
{
    int n,ans=0,maxi=0;
    cin>>n;
    for(int i=n;i>=1;i--)
    {
        int cntr=0;
        int num=i;
        while(num%2==0 && num>0)
        {
            cntr++;
            num/=2;
        }
        if(cntr>maxi)
        {
            maxi=cntr;
            ans=i;
        }
    }
    if(n==1)
        cout<<1;
    else
        cout<<ans;
    return 0;
}


Measured memory_bytes: 3628
k,q=map(int,input().split())
d=list(map(int,input().split()))
for i in range(q):
    n,x,m=map(int,input().split())
    l=[i%m if i%m!=0 else m for i in d]
    print(n-1-(x+((n-1)//k)*sum(l)+sum(l[:(n-1)%k]))//m+x//m)


Measured memory_bytes: 67164
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




int main()
{
    int N,K;
    cin >> N >> K;
    vector<int> d(K);
    vector<int> ans(N);

    int a;
    rep(i,K){
        cin >> d[i];
        rep(j,d[i]){
            cin >> a;
            a--;
            ans[a]++;
        }
    }

    int count = 0;
    rep(i,N){
        if(ans[i] == 0) count++;
    }

    cout << count << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n,m,k,ireq;
	cin>>n>>m>>k;
	ireq=n;
	int a[n],b[m];
	ll sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<m;i++)
		cin>>b[i];
	for(int i=0;i<n;i++){
		sum+=a[i];
	//	cout<<sum<<endl;
		if(sum>k){
			ireq=i;
			sum-=a[i];
			break;
		}
	}
	int ans=ireq-1,bp=0,best=-1;
//	cout<<ans<<endl;
	for(int i=ireq-1;i>=-1;i--){
		while(bp<m && sum+b[bp]<=k){
		//	cout<<sum<<endl;
			sum+=b[bp];
			bp++;
		}
			best=max(best,i+bp);
		//cout<<bp<<' '<<sum<<' '<<i<<' '<<best<<endl;
		if(i!=-1)
			sum-=a[i];
	}
	cout<<best+1<<endl;
	return 0;
}

Measured memory_bytes: 5192
#include <iostream>
#include <algorithm>
using namespace std ;
using ll = long long ;

int main(){
	ll k,a,b ;
	cin >> k >> a >> b ;
	k++ ;
	ll ans = k ;
	if(a<b){
		if(a+2<=k) ans = max(ans,b+(k-a-2)/2*(b-a)+(k-a-2)%2) ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        init(n);
        for (int i=0;i<q;i++) {
            if(in.nextInt()==0) {
                add(in.nextInt(), in.nextInt());
            }
            else {
                System.out.println(sum(in.nextInt(), in.nextInt()));
            }
        }
    }
     static int[] nodes;
    static int size;
    static void init(int n) {
        size=1;
        while (size<n)
            size*=2;
        nodes = new int[size+1];
    }
    static void add(int target, int value) {
        while (target<nodes.length) {
            nodes[target] += value;
            target += target&(-target);
        }
    }
    static int sum(int s, int t) {
        return sum(t) - sum(s-1);
    }
    static int sum(int t) {
        int res=0;
        while (t>0) {
            res += nodes[t];
            t -= t&(-t);
        }
        return res;
    }
}


Measured memory_bytes: 103772
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#define LL long long
using namespace std;
int main()
{
    int n;
    char s[105];
    while(~scanf("%d",&n))
    {
        scanf("%s",s);
        int cnt1=0;
        int cnt2=0;
        for (int i=0;i<n;i++){
            if (s[i]=='B'){
                cnt1++;
            }else {
                cnt2++;
            }
        }
        if (cnt1<cnt2){
            printf("Yes\n");
        }else {
            printf("No\n");
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
    ll Q, H, L, D, N;
	cin >> Q >> H >> L >> D >> N;
	H = min(H, Q * 2);
	L = min(L, H * 2);
	D = min(D, L * 2);
	cout << N / 2 * D + (N % 2) * L << endl;
}

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, m;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<int> a={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << a[n-1] << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000000000000ll
#define N 409
using namespace std;

int n,a[N][4]; ll ans,sum,p[N],q[4];
struct hsh{
	int tot,fst[20000003],sz[N],tp[N],nxt[N]; ll pnt[N];
	void ins(ll x,int y){
		int i,z=x%20000003;
		for (i=fst[z]; i; i=nxt[i]) if (pnt[i]==x){
			sz[i]+=y; return;
		}
		pnt[++tot]=x; sz[tot]=y;
		if ((x>>20)==(x&(1<<20)-1))
			tp[tot]=((x>>30)==(x&(1<<10)-1)?4:2);
		else tp[tot]=1;
		nxt[tot]=fst[z]; fst[z]=tot;
	}
	void solve(ll &x){
		int i,z=x%20000003;
		for (i=fst[z]; i; i=nxt[i]) if (pnt[i]==x){
			sum*=tp[i]*(sz[i]--);
			return;
		}
		x=-1; sum=0;
	}
}hsh;
ll calc(int x1,int x2,int x3,int x4){
	int num[4]={x1,x2,x3,x4},i,j; ll tmp,mn=inf;
	for (i=0; i<4; i++){
		for (j=0,tmp=0; j<4; j++) tmp=tmp<<10|num[(i+j)&3];
		mn=min(mn,tmp);
	}
	return mn;
}
int main(){
	scanf("%d",&n);
	int i,j,k,l;
	for (i=1; i<=n; i++){
		for (j=0; j<4; j++) scanf("%d",&a[i][j]);
		p[i]=calc(a[i][0],a[i][1],a[i][2],a[i][3]);
		hsh.ins(p[i],1);
	}
	for (i=1; i<n; i++){
		hsh.ins(p[i],-1);
		for (j=i+1; j<=n; j++){
			hsh.ins(p[j],-1);
			for (k=0; k<4; k++){
				for (l=0,sum=1; l<4; l++){
					q[l]=calc(a[i][(l+1)&3],a[i][l],a[j][(k-l+5)&3],a[j][(k-l+4)&3]);
					hsh.solve(q[l]);
				}
				ans+=sum;
				for (l=0; l<4; l++) if (q[l]!=-1) hsh.ins(q[l],1);
			}
			hsh.ins(p[j],1);
		}
		hsh.ins(p[i],1);
	}
	printf("%lld\n",ans/3);
	return 0;
}


Measured memory_bytes: 76160
import numpy as np

N, M, X = map(int, input().split())
A = np.array(list(map(int, input().split())))

ans = 0
if N <= X:
    ans = np.intersect1d(A[A > N], A[A < X]).shape[0]
else:
    ans = min(
        np.intersect1d(A[A > 0], A[A < X]).shape[0],
        np.intersect1d(A[A < N], A[A > X]).shape[0],
    )

print(ans)

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

using namespace std;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()

const int MX = (int)1e5 + 10;
// const int mod = (int)1e9 + 7;


// template<typename ForwardIxterator, typename T>
// ForwardIxterator first_less_than(ForwardIxterator fs, ForwardIxterator ls, T value){
//     auto it = lower_bound(fs, ls, value);
//     return it == fs ? ls : --it;
// }

int main(int argc, char* argv[]){

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

    // vector<int> a({1, 2, 3});
    // int x[3];

    // auto it = first_less_than(x, x + 3, 1);

    // cout << *it << endl;

    int k, x;
    cin >> k >> x;

    int mn = max(-1000000, x - k + 1);
    int mx = min(1000000, x + k - 1);

    for(int i = mn; i <= mx; ++i) cout << i << " ";

    return 0;
}


Measured memory_bytes: 256
///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<typename T>
using zet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 4;

int n, a[N], b[N];

void solve() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }

    ll res = 0;
    for (int i = n - 1; i >= 0; --i) {
        ll j = res + a[i];
        ll add = (b[i] - j % b[i]) % b[i];
        res += add;
    }

    cout << res << "\n";
}

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

    int z = 1;
    /// cin >> z;

    while (z--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 4400
#include <stdio.h>
int main(void){
  int d[3]={0,0,0};
  int i;
  d[0] = getc(stdin);
  d[1] = getc(stdin);
  d[2] = getc(stdin);
  for(i=0; i<3;i++){
    d[i]=d[i]-48;
    if (d[i]==1){
      d[i]=d[i]+8;
    }
    else{
      d[i]=d[i]-8;
    }
  }
  printf("%d%d%d", d[0], d[1], d[2]);
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;
#define LL long long
#define maxn 110
#define inf 0x3f3f3f3f

int G[maxn][maxn];
int n,m;
char c;
int low[maxn],col[maxn];

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			scanf(" %c",&c);
			G[i][j]=(c=='#');
			low[i]+=G[i][j];
			col[j]+=G[i][j];
		}
	for(int i=1;i<=n;i++){
		if(low[i]==0) continue;
		for(int j=1;j<=m;j++)
			if(col[j]==0) continue;
			else printf("%c",G[i][j]==1?'#':'.');
		puts("");
	}

	return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

const INF = 100000000

func main() {
	sc.Split(bufio.ScanWords)
	n := readInt()
	x := make([]int, n)
	for i := 0; i < n; i++ {
		x[i] = readInt()
	}

	min := getMin(x)
	max := getMax(x)

	minP := INF
	for i := min; i <= max; i++ {
		p := 0
		for j := 0; j < n; j++ {
			p += (x[j] - i) * (x[j] - i)
		}
		if p < minP {
			minP = p
		}
	}
	fmt.Println(minP)
}

func getMin(x []int) int {
	min := 100
	for _, v := range x {
		if v < min {
			min = v
		}
	}
	return min
}

func getMax(x []int) int {
	max := 0
	for _, v := range x {
		if v > max {
			max = v
		}
	}
	return max
}


Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;

int main()
{
    int n;
    cin>>n;
    string s,s1="";
    cin>>s;
    set<char>data;
    s1+=s[0];
    for(int i=1;i<s.size();i++)
    {
        if(s[i-1]!=s[i])
        {
            s1+=s[i];
        }
    }
    cout<<s1.size()<<endl;
    return 0;

}

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

struct Node{
   int key;
   Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
   Node *y=NIL;
   Node *x=root;
   Node *z=new Node;

   z->key=k;
   z->left=NIL;
   z->right=NIL;

   while(x!=NIL){
      y=x;
      if(z->key < x->key) x=x->left;
      else x=x->right;
   }
   
   z->parent=y;
   if(y==NIL) root=z;
   else{
      if(z->key<y->key) y->left=z;
      else y->right=z;
   }
}

Node *find(Node *u, int k){
   while(u!=NIL && k!=u->key){
      if(k<u->key) u=u->left;
      else u=u->right;
   }
   return u;
}

Node *getMinimum(Node *u){
   while(u->left!=NIL) u=u->left;
   return u;
}

Node *getSuccessor(Node *u){
   if(u->right!=NIL) return getMinimum(u->right);
   Node *y=u->parent;
   while(y!=NIL && u==y->right){
      u=y;
      y=y->parent;
   }
   return y;
}

void treeDelete(Node *u){
   Node *y;
   Node *x;
   if(u->left==NIL || u->right==NIL) y=u;
   else y=getSuccessor(u);
   if(y->left!=NIL) x=y->left;
   else x=y->right;
   if(x!=NIL) x->parent=y->parent;
   if(y->parent==NIL) root=x;
   else{
      if(y==y->parent->left) y->parent->left=x;
      else y->parent->right=x;
   }
   if(y!=u) u->key=y->key;

   delete y;
}

void inorder(Node *u){
   if(u==NIL) return;
   inorder(u->left);
   cout << " " << u->key;
   inorder(u->right);
}

void preorder(Node *u){
   if(u==NIL) return;
   cout << " " << u->key;
   preorder(u->left);
   preorder(u->right);
}

int main(){
   int n, x;
   string com;
   cin >> n;

   for(int i=0; i<n; i++){
      cin >> com;
      if(com=="insert"){
         cin >> x;
         insert(x);
      }
      else if(com=="print"){
         inorder(root);
         cout << endl;
         preorder(root);
         cout << endl;
      }
      else if(com[0]=='f'){
         cin >> x;
         Node *t=find(root, x);
         if(t!=NIL) cout << "yes" << endl;
         else cout << "no" << endl;
      }
      else if(com=="delete"){
         cin >> x;
         treeDelete(find(root, x));
      }
   }

   return 0;
}


Measured memory_bytes: 21936
fun main(args: Array<String>) {
    val L = listOf(1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51)
    val K = nextInt()
    val ans = L[K - 1]
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())


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

const int MAX_N = 1500000;
long long BASE = 217;
long long MOD1 = 1000000007;
long long MOD2 = 1000000009;

string S, T;
long long power1[1 << 22], power2[1 << 22];
long long hashs1[1 << 22], hashs2[1 << 22];
long long hasht1[1 << 22], hasht2[1 << 22];

void init() {
	string U1 = ""; while (U1.size() < MAX_N * 2) U1 += S;
	string U2 = ""; while (U2.size() < MAX_N * 2) U2 += T;
	power1[0] = 1; for (int i = 1; i <= MAX_N * 2; i++) power1[i] = (BASE * power1[i - 1]) % MOD1;
	power2[0] = 1; for (int i = 1; i <= MAX_N * 2; i++) power2[i] = (BASE * power2[i - 1]) % MOD2;
	for (int i = 1; i <= MAX_N * 2; i++) hashs1[i] = (BASE * hashs1[i - 1] + (long long)(U1[i - 1] - 'a' + 1)) % MOD1;
	for (int i = 1; i <= MAX_N * 2; i++) hashs2[i] = (BASE * hashs2[i - 1] + (long long)(U1[i - 1] - 'a' + 1)) % MOD2;
	for (int i = 1; i <= MAX_N * 2; i++) hasht1[i] = (BASE * hasht1[i - 1] + (long long)(U2[i - 1] - 'a' + 1)) % MOD1;
	for (int i = 1; i <= MAX_N * 2; i++) hasht2[i] = (BASE * hasht2[i - 1] + (long long)(U2[i - 1] - 'a' + 1)) % MOD2;
}

bool solve(int pos) {
	int len = pos * T.size();
	long long val1 = hasht1[len], val2 = hasht2[len];
	for (int i = 0; i <= MAX_N * 2 - len; i++) {
		long long cur1 = (hashs1[i + len] - hashs1[i] * power1[len] + MOD1 * MOD1) % MOD1;
		long long cur2 = (hashs2[i + len] - hashs2[i] * power2[len] + MOD2 * MOD2) % MOD2;
		if (val1 == cur1 && val2 == cur2) return true;
	}
	return false;
}

int main() {
	cin >> S >> T;
	init();
	
	int cl = 0, cr = MAX_N / (int)T.size(), cm, maxn = 0; cr++;
	for (int i = 0; i < 24; i++) {
		cm = ((cl + cr) >> 1);
		bool I = solve(cm);
		if (I == true) { cl = cm; maxn = max(maxn, cm); }
		else { cr = cm; }
	}
	if (cm == MAX_N / (int)T.size()) cout << "-1" << endl;
	else cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 159652
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int INF=1e9;
const ll MOD=1e9+7;

int N;
string S;

int main(){

cin>>N>>S; 

int cnt=0,L=0,R=0;

for(int i=0; i<N; i++){
    if(S[i]=='(') cnt++;
    if(S[i]==')') cnt--;   
    if(cnt<0){
        L++; cnt=0;
    }
}

R=cnt;
//cout<<L<<" "<<R<<endl;
for(int i=0; i<L; i++) S="("+S;
for(int i=0; i<R; i++) S=S+")";
cout<<S<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long int
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pb push_back
#define Max(x,y,z) max(x,max(y,z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x)       (ll)x.size()
#define pi 3.1415926536
#define mod 1000000007
using namespace std;
const int inf=1e9+5;
//const int N = 1e4+5;
/*bool vis[N];
ll a[N];*/
/*bool sortinrev(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
     return (a.f>b.f);
}*/
void solve()
{   ll n,m,k,y,x,res=0,l,r,cnt0=0,z,sum1=0,cnt1=0,h,res1,ans=0,sum=0;
    //scanf("%d",&n);
    //scanf("%d",&k);
    cin>>n>>k;
    ll ar[n];
    rep(i,0,n) cin>>ar[i];//scanf("%d",&ar[i]);
    vector<ll> dp(n,inf);
    dp[0]=0;
    //dp[1]=abs(ar[0]-ar[1]);
    for(ll i=0;i<n;++i)
    {
        for(ll j=i+1;j<=i+k;++j)
            if(j<n)
            dp[j]=min(dp[i]+abs(ar[i]-ar[j]),dp[j]);
    }
    //printf("%d",dp[n-1]);
    cout<<dp[n-1];
}
int main()
{   speed_up
    ll t;
   //cin>>t;
    t=1;
    while(t--)
        solve();

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef   long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.141592653

ll pre[200005],pos[200005];

int main() 
{
    FAST;
    ll n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        pre[i]=(pre[i-1]+i)%A;
    pos[n]=n;
    for(int i=n-1;i>=0;i--)
        pos[i]=(pos[i+1]+i)%A;
    ll ans=0;
    for(int i=k;i<=n+1;i++)
        ans=(ans+A+((pos[n-i+1]-pre[i-1]+1)%A))%A;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6720
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n, k;
	cin >> n >> k;
	double ans=0;
	for (int i=1;i<=n;i++){ 
		int cur=i;
		double eve=1.0/n;
		while (1){
			if (cur>=k)
				break;
			cur*=2;
			eve/=2.0;
		}
		ans+=eve;
	}	
	printf("%.12f",ans);
	return 0;
} 

Measured memory_bytes: 256