akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.TreeSet;
public class Main {
  public static void main(String[] args) {
    Main m = new Main();
    m.run();
  }
  private void run() {
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
      String[] p = br.readLine().split("\\s+");
      int n = Integer.parseInt(p[0]);
      int q = Integer.parseInt(p[1]);
      Roadwork[] r = new Roadwork[2*n];
      for (int i=0;i<2*n;i+=2) {
        p = br.readLine().split("\\s+");
        int s = Integer.parseInt(p[0]);
        int t = Integer.parseInt(p[1]);
        int x = Integer.parseInt(p[2]);
        r[i] = new Roadwork(s-x,1,x,i/2);
        r[i+1] = new Roadwork(t-x,-1,x,i/2);
      }
      Arrays.sort(r,Comparator.comparingInt(w -> w.t));
      int idx = -1;
      TreeSet<Roadwork> undergo = new TreeSet<>(Comparator.comparingInt(w -> w.x));
      StringBuilder sb = new StringBuilder();
      for (int k=0;k<q;k++) {
        int d = Integer.parseInt(br.readLine());
        while (idx < 2*n-1 && r[idx+1].t <= d) {
          idx++;
          if (r[idx].f > 0) undergo.add(new Roadwork(0,0,r[idx].x,r[idx].i));
          if (r[idx].f < 0) undergo.remove(new Roadwork(0,0,r[idx].x,r[idx].i));
        }
        if (undergo.isEmpty()) {
          sb.append(-1).append("\n");
        } else {
          sb.append(undergo.first().x).append("\n");
        }
      }
      System.out.print(sb);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  private class Roadwork {
    private int t,f,x,i;
    Roadwork(int t,int f,int x,int i) {
      this.t = t;
      this.f = f;
      this.x = x;
      this.i = i;
    }
    @Override
    public int hashCode() {
      int prime = 31;
      int result = 1;
      result = prime*result+t;
      result = prime*result+f;
      result = prime*result+x;
      result = prime*result+i;
      return result;
    }
    @Override
    public boolean equals(Object obj) {
      if (this == obj) return true;
      if (obj == null) return false;
      if (getClass() != obj.getClass()) return false;
      Roadwork other = (Roadwork)obj;
      return t == other.t && f == other.f && x == other.x && i == other.i;
    }
  }
}

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

#define MOD 1000000007 // 10^9 + 7
#define MAX 510000



long long int fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long int COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
  // 前処理
  COMinit();

  int n, k;

  scanf("%d%d", &n, &k);

  for (int i = 1; i <= k; i++) {
    long long int ans = ( COM(k-1, i-1) * COM(n-k+1, i) ) % MOD;
    printf("%lld\n", ans);
  }

  return 0;
}



Measured memory_bytes: 12160
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static boolean possible(List<Integer> w, int n, int k, int P) {
		int current = 0;
		k--; // ???????????£???????????????????????°
		for (int c : w) {
			if (current + c > P) {
				if (k > 0) {
					k--;
					if (c <= P)
						current = c;
					else 
						return false; 
				} else {
					return false;
				}
			} else {
				current += c;
			}
		}
		return true;
	}
	
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		// BufferedReader br = new BufferedReader(new FileReader("in2.txt"));
		String[] line = br.readLine().split(" ");
		int n = Integer.parseInt(line[0]);
		int k = Integer.parseInt(line[1]);
		List<Integer> w = new ArrayList<Integer>();
		for (int i = 0; i < n; i++)
			w.add(Integer.parseInt(br.readLine()));
		
		// O(kn^2)?????¢?????´??????????????????????????????...????????????(?????¶)
		// ????????????????????????O(kn)?????????????§£?????????????????????????????????...
		// List<List<Integer>> P = new ArrayList<List<Integer>>();
		// List<Integer> P0 = new ArrayList<Integer>();
		// P0.add(w.get(0));
		// for (int j = 1; j < n; j++)
		// 	P0.add(P0.get(j - 1) + w.get(j));
		// P.add(P0);
		// for (int i = 1; i < k; i++) {
		// 	List<Integer> Pk = new ArrayList<Integer>();
		// 	for (int j = 0; j < n; j++) {
		// 		int min = P.get(i - 1).get(j);
		// 		int sum = 0;
		// 		for (int l = 0; l < j; l++) {  // j??????????????????????????????l+1???????????????
		// 			sum += w.get(j - l);
		// 			if (min < sum)
		// 				break;
		// 			min = Math.max(P.get(i - 1).get(j - l - 1), sum);
		// 		}
		// 		Pk.add(min);
		// 	}
		// 	P.add(Pk);
		// }
		// System.out.println(P.get(k - 1).get(n - 1));
		
		// ??????P????????????????????????????????????????????????????????????????????¨???????°????
		// ???????????¨??????2?????¢?´¢??§?????£?????????O(nlnP)??§???????????????
		// System.out.println(possible(w, n, k, 6));
		int u = 1000000000, l = 1;  // l????????????u???????????????
		while (u - l > 1) {
			int mid = (u + l) / 2 - 1;
			if (possible(w, n, k, mid))
				u = mid + 1;
			else
				l = mid + 1;
		}
		System.out.println(l);
	}
}

Measured memory_bytes: 31564
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return a;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

void solve(void){
    int n;
    cin >> n;
    int h[n];
    rep(i,0,n) cin >> h[i];
    int dp[n];
    dp[0] = 0;
    rep(i,1,n){
        dp[i] = INF;
    }
    
    rep(i,0,n){
        chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
        if(i > 1) chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n-1] << endl;

}

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

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
const int dx[] = {0,0,-1,1};
const int dy[] = {1,-1,0,0};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

void bfs(map<PII,vector<PII>>& mp,int h,int w){

  int ci=0,cj=0;
  deque<PII> que;
  que.push_back(PII(ci,cj));

  VVI dist(h,VI(w,-1));
  dist[0][0] = 1;
  while(que.empty() == false){
    PII p = que.front();
    que.pop_front();
    ci = p.first, cj = p.second;
    for(PII np : mp[p]){
      if(dist[np.first][np.second] != -1) continue;
      dist[np.first][np.second] = dist[ci][cj] + 1;
      que.push_back(np);
    }
  }
  // rep(i,h){
  //   rep(j,w){
  //     cout << dist[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  if(dist[h-1][w-1] == -1 ) cout << 0 << endl;
  else cout << dist[h-1][w-1] << endl;

}

int main(){
  int h,w;
  while(true){
    cin >> w >> h;
    if(w == 0 && h == 0 ) break;
    vector<string> b(2*h-1);
    char ch;
    rep(i,2*h-1){
      rep(j,(i%2?(w):(w-1))){
        cin >> ch;
        b[i].push_back(ch);
      }
    }

    vector<string> board(2*h-1);

    rep(i,2*h-1){
      int cnt_0 = 0;
      int cnt_1 = 0;
      rep(j,2*w-1){
        if(i%2 == 0){
          if(j%2==0) board[i].push_back('.');
          else{
            board[i].push_back(b[i][cnt_0]);
            cnt_0++;
          }
        }else{
          if(j%2==1) board[i].push_back('.');
          else board[i].push_back(b[i][cnt_1]),cnt_1++;;
        }
      }
    }

    map<PII,vector<PII> > mp;
    int gi = 0;
    int gj = 0;
    rep(i,2*h-1){
      if(i % 2 == 1) continue;
      gj = 0;
      rep(j,2*w-1){
        if(j%2==1) continue;
        rep(dir,4){
          int ni = i+dy[dir];
          int nj = j+dx[dir];
          if(ni >= 0 && nj >= 0 && ni < (2*h-1) && nj < (2*w-1) && board[ni][nj] == '0'){
            mp[PII(gi,gj)].push_back(PII(gi+dy[dir],gj+dx[dir]));
          }
        }
        gj++;
      }
      gi++;
    }
    bfs(mp, h, w);

  }
  return 0;
}



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

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> X( M );
	for( int i = 0; i < M; i++ ) {
		cin >> X[i];
	}

	int ans = 0;
	if( M > N ) {
		sort( X.begin(), X.end() );
		priority_queue<int> que;
		for( int i = 0; i < M - 1; i++ ) {
			que.push( X[i + 1] - X[i] );
		}
		ans = X[M - 1] - X[0];
		for( int i = 0; i < N - 1; i++ ) {
			int l = que.top();
			que.pop();
			ans -= l;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 4204
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b){
        swap(a,b);
    }
    if(b>c){
        swap(b,c);
    }
    if(a>b){
        swap(a,b);
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}



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

signed main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int a, b; cin >> a >> b;

    cout << (a + b == 15 ? '+' : (a * b == 15 ? '*' : 'x')) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using ll = long long int;
using namespace std;

namespace AOJ {
    ll gcd(ll x, ll y) {
        if (y == 0)
            return x;
        return gcd(y, x % y);
    }
} // namespace AOJ
int main() {

    fastIO;
    ll x, y;
    cin >> x >> y;
    cout << AOJ::gcd(x, y) << endl;
}



Measured memory_bytes: 3168
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();
        Arrays.sort(a);
        long min = Integer.MAX_VALUE;
        int pos = 0;

        for (int j = a[0]; j <= a[n - 1]; j++) {
            long sum = 0;
            for (int i = 0; i < n; i++) {
                sum += Math.abs(a[i] - j) * Math.abs(a[i] - j);

            }
            if (sum < min) {
                min = sum;
                pos = j;
            }
        }
        System.out.println(min);

    }
}

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

int main() {
  string s;
  cin >> s;
  if(s[0]==s[1] && s[1]==s[2]) {
    cout << "Yes" << endl;
  } else {
    if(s[1]==s[2] && s[2]==s[3]) {
    cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
// Mon Aug 24 16:24:09 IST 2020        
#include <bits/stdc++.h>        
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(ii,a,b)       for(int ii = (int)a ; ii < (int)b  ; ii++ )
#define scan(any)          for(auto &i:any) cin>>i;
#define debug(x)           cerr << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int64              long long   
#define all(x)             (x).begin(),(x).end() 
#define ff                 first
#define ss                 second
#define pppp               pair <int,int> 
#define flushOff           fflush(stdout) 
#define precise(x)         cout << fixed << setprecision(12) << x << '\n'; 
using namespace std ;    
// policy based   
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
 
const int MOD1 = 1e9+7;
const int MOD2 = 1e9+9;
const double pi = 3.141592653589793238;
const int INF = 2e9+7; 
const int N = 2e5+7;
struct compare{
    bool operator()(pair <int,int> A, pair <int,int> B){
        if(A.first == B.first)
            return A.second > B.second;
        return A.first > B.first;
    }
}; 
void print(vector <int>v){
    for(int t : v){
        cout << t << ' ';
    }
    cout << '\n';
}
int tests(){  
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    if(K <= A)
        return cout << K << '\n',0;
    if(K <= B)
        return cout << A << '\n',0;
    cout << A-(K-(A+B)) << '\n';
    return 0;
}    
int main(){
    I__O ;      
    int cases = 1 ;  
    // cin >> cases ;
    while(cases--)
        tests(); 
    return 0 ; 
}
 

Measured memory_bytes: 3632
class LazySegmentTree
	def initialize(n, l = 0, r = n-1)
		@range_min = l
		@range_max = r
		@start = 0
		@between = 0
		@end = 0
		if l == r
		else
			c = (l + r) / 2
			@left_child = self.class.new(n, l, c)
			@right_child = self.class.new(n, c+1, r)
		end
	end

	attr_reader :range_min, :range_max

	def add_start(x, bits)
		if @range_min == @range_max
			@start |= bits
		else
			if x <= @left_child.range_max
				@left_child.add_start(x, bits)
			else
				@right_child.add_start(x, bits)
			end
		end
	end

	def add_end(x, bits)
		if @range_min == @range_max
			@end |= bits
		else
			if x <= @left_child.range_max
				@left_child.add_end(x, bits)
			else
				@right_child.add_end(x, bits)
			end
		end
	end

	def add_between(x, y, bits)
		return if x > y

		if x == @range_min && y == @range_max
			@between |= bits
		else
			lr = @left_child.range_max
			@left_child.add_between(x, lr < y ? lr : y, bits)
			rl = @right_child.range_min
			@right_child.add_between(rl > x ? rl : x, y, bits)
		end
	end

	def force
		if @range_min != @range_max
			@left_child.take(@start, @between, @end)
			@right_child.take(@start, @between, @end)
		end
		@star = @between = @end = 0
	end

	def take(start, between, finish)
		@start |= start
		@between |= between
		@end |= finish
	end

	def net_start_count(x)
		if @range_min == @range_max
			bits = @start
			bits -= bits & @end
			bits -= bits & @between
			bits.to_s(2).count("1")
		else
			force
			if x <= @left_child.range_max
				@left_child.net_start_count(x)
			else
				@right_child.net_start_count(x)
			end
		end
	end

	def net_end_count(x)
		if @range_min == @range_max
			bits = @end
			bits -= bits & @start
			bits -= bits & @between
			bits.to_s(2).count("1")
		else force
			if x <= @left_child.range_max
				@left_child.net_end_count(x)
			else
				@right_child.net_end_count(x)
			end
		end
	end
end


ones = [0]
10000.times{
	ones << ((ones[-1] << 1) | 1)
}

t = Time.new

loop {
	n, r = gets.split.map(&:to_i)
	break if n == 0


	a = (1..n).map{ gets.split.map(&:to_i) }
	max_x = a.map{|_,_,x2,_| x2}.max
	max_y = a.map{|_,_,_,y2| y2}.max
	v_st = LazySegmentTree.new(max_x+1)
	h_st = LazySegmentTree.new(max_y+1)

	a.each {|x1, y1, x2, y2|
		bits = ones[y2-y1] << y1
		v_st.add_start(x1, bits)
		v_st.add_between(x1+1, x2-1, bits) if x1+1 < x2
		v_st.add_end(x2, bits)
		bits = ones[x2-x1] << x1
		h_st.add_start(y1, bits)
		h_st.add_between(y1+1, y2-1, bits) if y1+1 < y2
		h_st.add_end(y2, bits)
	}

	area = 0
	for x in 0..max_x
		area += v_st.net_start_count(x) * (10000-x)
		area -= v_st.net_end_count(x) * (10000-x)
	end
	p area

	if r == 2
		len = 0
		for x in 0..max_x
			len += v_st.net_start_count(x)
			len += v_st.net_end_count(x)
		end
		for y in 0..max_y
			len += h_st.net_start_count(y)
			len += h_st.net_end_count(y)
		end
		p len
	end
}

Measured memory_bytes: 87180
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll> 
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s,t,u;cin>>s>>t;
  ll a,b;cin>>a>>b>>u;
  if(s==u) printf("%lld %lld\n",a-1,b);else printf("%lld %lld\n",a,b-1); 
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
mod = 10 ** 9 + 7

n, k = map(int, input().split())

rst = 0
for i in range(k, n+2):
    _min = (i * (i - 1)) // 2
    _max = (i * ((n-i+1) + (n))) // 2
    rst += _max - _min + 1
    rst %= mod

print(rst)


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

vector<bool> sf(11);
int main(void){
	int N,M,ans = 0;
	cin >> N >> M;
	int k[15],s[M][10],p[15];
	for(int i=0;i<M;i++){
		cin >> k[i];
		for(int j=0;j<k[i];j++){
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	for(int i=0;i<M;i++)cin>>p[i];
	
	for(int i=0;i< 1<<N;i++){
		fill(sf.begin(),sf.end(),false);
		for(int j=0;j<N;j++){
			if((i>>j)&1){
				sf[j] = true;
			}
		}
		bool flag = true;
		for(int j=0;j<M;j++){
			int cnt = 0;
			for(int a=0;a<k[j];a++){
				if(sf[s[j][a]]==true)cnt++;
			}
			if(cnt%2 == p[j]){
			}else{
				flag = false;
				break;
			}
		}
		if(flag)ans++;
	}
	cout << ans << endl;
}

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

int main(int argc, char *argv[])
{
  int n;
  std::cin >> n;
  std::vector<double> v;
  for (int i = 0; i < n; i++)
  {
    int v_i;
    std::cin >> v_i;
    v.push_back((double)v_i);
  }
  while (v.size() > 1)
  {
    std::sort(v.begin(), v.end());
    v[1] = (v[0] + v[1]) * 0.5;
    v.erase(v.begin());
  }
  std::cout << v[0];
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
		int n;
	    cin>>n; int sum=0;
	    vector<int> A(n);
	    for(int i=0;i<n;i++)
	    {
	        cin>>A[i];
	        sum+=A[i];
	    }
	    vector<vector<int>> dp(n,vector<int>(n));
	    for(int i=0;i<n;i++)
	    	dp[i][i]=A[i];
	    for(int gap=1;gap<n;gap++)
	    {
	        for(int i=0,j=gap;j<n;j++,i++)
	        {
	            int x=(i+2<=j)?dp[i+2][j]:0;
	            int y=(i+1<=j-1)?dp[i+1][j-1]:0;
	            int z=(i<=j-2)?dp[i][j-2]:0;
	            dp[i][j]=max(A[i] + min(x, y), A[j] + min(y, z));
	        }
	        
	    }
	    int X=dp[0][n-1];
	    cout<<2*X-sum<<endl;
	
}	

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

int main(){

 string s,t;
  cin>>s>>t;
 
int slen= s.length();
int tlen= t.length();

int ans=9999999;
int count=tlen;
for(int i=0;i<slen-tlen+1;i++){
  count=0;
	for(int j=0,k=i;j<tlen;j++,k++){
    	if(s[k]!=t[j])
          count++;
	}
  ans= min(ans, count);
}
cout<<ans; 
  
return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

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

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

string s;
void input(){
    fast_io();
    cin >> s;
}

string shrink(string t,char x){
    string ret;
    for (int i = 0; i < t.length()-1; i++)
    {
        if(t[i]==x || t[i+1]==x) ret += x;
        else ret += t[i];
    }
    return ret;    
}

bool alleq(string s, char x){
    for (int i = 0; i < s.length(); i++)
    {
        if(s[i]!=x) return false;
    }
    return true;    
}

int calc(string s, char x){
    int ret = 0;
    while(!alleq(s,x)){s = shrink(s,x); ret++;}
    return ret;
}

int solve(){
    int ans = 200;
    for (char x = 'a'; x <= 'z'; x++)
    {
        ans = min(ans,calc(s,x));
    }
    cout << ans << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

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

int keta(int N) {
	int count = 1;
	while (N / 10 > 0) {
		N /= 10;
		count++;
	}
	return count;
}

int main() {
	int a, b;
	cin >> a >> b;
	int answer;
	answer = b + a * pow(10,keta(b));
	rep(i, 1000) {
		if (i == 0) {
			continue;
		}
		if (i * i == answer) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;



signed main(){
    ll n,h,ans=0;cin>>n>>h;

    vector<ll> v(n);
    vector<ll> b(n);
    for(int i=0;i < n;i++)
    {
        cin>>v[i]>>b[i];
    }
    sort(v.begin(),v.end());
    sort(b.begin(),b.end());

    ll itr=lower_bound(all(b),v[n-1])-b.begin();

    for(int i=n-1;itr<=i && h>0;i--)
    {
        h-=b.at(i);
        ans++;
    }

    if(h>0)ans+=(h+v[n-1]-1)/v[n-1];

    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(){
    int x,i,div;
    int pn=0;
    scanf("%d",&x);

    for(;;){
        if(x==2){
            pn=x;
            break;
        }
        for(i=2;i<x;i++){
            div = x % i;
            if(div==0)
            break;
            if(x-1 == i){
                pn = x;
                break;
            }
        }
        if(pn != 0)
        break;
        else
        x= x+1;
    }
    printf("%d",pn);
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> data(n);
    rep(i, n)
    {
        data.at(i) = make_pair(i,0);
        if (i == 0)
        {
            continue;
        }
        else
        {
            int josi;
            cin >> josi;
            data.at(josi - 1).second++;
        }
    }

    rep(i, n)
    {
        cout << data.at(i).second << endl;
    }

    return 0;
}

Measured memory_bytes: 4844
a,b,c = map(int, input().split())

ans_list = [0] * (a-1)

for i in range(1,a+1):
    for j in range(i+1,a+1):
        normal = j-i
        abnormal = abs(b-i)+1+abs(j-c)
        if (normal <= abnormal):
            ans = normal
        else:
            ans = abnormal
        ans_list[ans-1] += 1
print(*ans_list, sep='\n')


Measured memory_bytes: 3444
#include <stdio.h>
int main(){
    int str[200000],max,min;
    int j,i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&str[i]);
    min=str[0];
    max=str[1]-str[0];
    for(j=1;j<n;j++){
        if(max<str[j]-min)
            max=str[j]-min;
         
        if(min>str[j])
            min=str[j];
    }
    printf("%d\n",max);
     
    return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define ll long long

template<class T>
void changeMax(T&a, const T b){if(a < b) a = b;}
template<class T>
void changeMin(T&a, const T b){if(a > b) a = b;}


template<class T>
void changeIdxMax(T&a, const T b, int&i, int j){
  if(a < b){
    a = b;
    i = j;
  }
}
template<class T>
void changeIdxMin(T&a, const T b, int&i, int j){
  if(a > b){
    a = b;
    i = j;
  }
}


int main(){
  int n,a,b; cin >> n >> a >> b;
  cout << min(n*a,b) << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter
N, K, Q = map(int, input().split())

result = ["No"]*N
Npoint = [K-Q]*N

Alist = [int(input())-1 for _ in range(Q)]

if K > Q:
    for _ in range(N):
        print("Yes")
    sys.exit()

Alist = Counter(Alist)

for k, v in Alist.items():
    Npoint[k] += v
    if Npoint[k] >= 1:
        result[k] = "Yes"

for i in result:
    print(i)


Measured memory_bytes: 18144
#include<iostream>

using namespace std;

int main()
{
	int mark[5], x{};

	for (int i = 0; i < 5; i++)
	{
		cin >> mark[i];
		if (mark[i] == 0)
			x = i + 1;
	}
	cout << x;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pi 3.141592653589793116
#define mod 1e9+7
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int main() {
  off;
  int t;
  //cin>>t;
  t=1;
  while(t--){  
      multiset <long long > q,o;
      int x,y,z,k;
      cin>>x>>y>>z>>k;
      long long temp;
      vector <long long > a,b,c;
      for(int i=0;i<x;i++)
          { cin>>temp;
              a.push_back(temp);
          }
       for(int i=0;i<y;i++)
          { cin>>temp;
              b.push_back(temp);
          }
         for(int i=0;i<z;i++)
          { cin>>temp;
              c.push_back(temp);
          }

          sort(a.begin(),a.end(),greater <long long>());
          sort(b.begin(),b.end(),greater <long long>());
          sort(c.begin(),c.end(),greater <long long>());
          //cout<<a[0]<<" "<<b[0]<<" "<<c[0]<<" "<<(a[1]+c[0]+b[0])<<"\n";
          long long min1=LLONG_MAX;
          for(int i=0;i<x;i++)
            {
                for(int j=0;j<y;j++)
                    {
                        for(int w=0;w<z;w++)
                            {  
                               long long sum=(a[i]+b[j]+c[w]);
                               
                               if(q.size()<k)
                                 {q.insert(-sum);o.insert(sum);}
                               else if(q.size()==k && (*o.begin())<sum)
                                  { 
                                     multiset<long long>::iterator it=q.end();
                                     it--;
                                     q.erase(it);
                                     o.erase(o.begin());
                                     o.insert(sum);
                                     q.insert(-sum);
                                  }
                                else
                                   break;  
                               
                            }
                    }
            }
           //cout<<q.size()<<" "; 
          for(auto it:q)
            {
                cout<<-it<<"\n";
                //q.pop();
            }      
  }
    return 0;
}

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

int main() {
  string s, t, key = "keyence";
  cin >> s;

  int n = s.size();

  for (int i = 0; i < n; i++) {
    for (int j = 1; j < n; j++) {
      if (s.substr(0, i) + s.substr(j) == key) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits//stdc++.h>
using namespace std;
int in(void){int x;cin>>x;return x;}
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define ll long long int
long long int dx[4]={1,0,-1,0};
long long int dy[4]={0,1,0,-1};
int main() {
	int x=0,y=0,z=0;
	int n,a,b;
	cin>>n>>a>>b;
	int s[n];
	rep(i,0,n){
		cin>>s[i];
		if(s[i]<=a)x++;
		else if(s[i]>=b+1)z++;
		else y++;
	}
	int min=x;
	if(min>z)min=z;
	if(min>y)min=y;
	cout<<min;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
const char* solve() {
    int N;
    cin >> N;
    vector<int> H(N);
    for (int& i : H) cin >> i;
    int tmp = H.back();
    for (auto itr = H.crbegin(); itr != H.crend(); ++itr) {
        if (*itr > tmp + 1) return "No";
        if (*itr <= tmp) tmp = *itr;
    }
    return "Yes";
}
int main() {
    cout << solve() << endl;
}

Measured memory_bytes: 640
I,O,_,J,L,_,_ = map(int,input().split())
ans1 = O + I-I%2 + J-J%2 + L-L%2
ans2 = 0
if I and J and L:
    I,J,L = I-1,J-1,L-1
    ans2 = 3 + O + I-I%2 + J-J%2 + L-L%2
print(max(ans1,ans2))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int main(){
    int n, m, ans=0;
    cin >> n >> m;
    int A[m] = {};
    rep(i, n){
        int k;
        R k;
        rep(j, k){
            int a;
            R a;
            A[a-1]+=1;
        }
    }
    rep(i, m){
        if(A[i]==n)ans+=1;
    }
    co(ans);
}


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

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

    std::vector<std::pair<int, int>> v(N);
    for (int i = 0; i < N; i++) {
        int A, B;
        std::cin >> A >> B;
        v[i] = std::make_pair(A, B);
    }

    std::sort(v.begin(), v.end(), [](auto p1, auto p2) {
        return p1.second > p2.second;
    });

    int ans = 0;
    std::vector<int> table(M, M);
    for (int i = 0; i < N; i++) {
        int now = M - v[i].first;

        if (now < 0) continue;

        while (0 <= now) {
            if (table[now] == M) {
                ans += v[i].second;
                table[now] = now - 1;
                break;
            }
            now = table[now]--;
        }
    }
    std::cout << ans << "\n";
}

Measured memory_bytes: 1408
#include<iostream>

int main () {
  int a;
  std::cin >> a;
  if (a == 1) {
    std::cout << "Hello World" << std::endl;
  }
  else {
    int b, c;
    std::cin >> b >> c;
    std::cout << b + c << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a,n) a, a + n
#define fo(i,n) for(int i =0;i<n;i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

int32_t main() {

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;

    int t ;
    cin >> t ;
    int count1 = 0, count2 = 0, count3 = 0, count4 = 0;
    while ( t-- ) {
        string s;
        cin >> s;
        if (s == "AC") {
            count1++;
        }
        else if ( s == "WA") {
            count2++;
        }
        else if ( s == "TLE") {
            count3++;
        }
        else
            count4++;

    }


    cout << "AC " << "x " << count1 << endl;
    cout << "WA " << "x " << count2 << endl;
    cout << "TLE " << "x " << count3 << endl;
    cout << "RE " << "x " << count4 << endl;

    return 0 ;

}

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


int main(){
    int N;
    vector<int> A(9);
    for(int i; i < 9; i++){
        cin >> A.at(i);
    }
    cin >> N;
    vector<int> B(N);
    for(int i; i < N; i++){
        cin >> B.at(i);
    }
    for(int i=0; i < 9; i++){
        for(int j=0; j < N; j++){
            if(A.at(i)==B.at(j)){
                A.at(i)= 150  ;    //合っているところは150に書き換え
            }
        }
    }
    bool judge=false;

    //横を調べる
    //盾を調べる
    if(A.at(0)==A.at(1) and A.at(0)==A.at(2)) judge = true;
    if(A.at(3)==A.at(4) and A.at(3)==A.at(5)) judge = true;
    if(A.at(6)==A.at(7) and A.at(6)==A.at(8)) judge = true;
    if(A.at(0)==A.at(3) and A.at(0)==A.at(6)) judge = true;
    if(A.at(1)==A.at(4) and A.at(7)==A.at(1)) judge = true;
    if(A.at(2)==A.at(5) and A.at(2)==A.at(8)) judge = true;
    if(A.at(0)==A.at(4) and A.at(0)==A.at(8)) judge = true;
    if(A.at(2)==A.at(4) and A.at(2)==A.at(6)) judge = true;

    if(judge) cout << "Yes";
    else cout << "No";

    //斜めを調べる

}

Measured memory_bytes: 256
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    nums = list(map(lambda x: int(x), inputs[0]))
    opr_num = len(nums) - 1
    opr_pattern = 2 ** opr_num

    total = 0
    for opr_digit in range(opr_pattern):
        oprs = []
        tmp_opr_digit = opr_digit
        for _ in range(0, opr_num):
            # print(tmp_opr_digit)
            if tmp_opr_digit & 1 == 1:
                oprs.append("+")
            else:
                oprs.append("")
            tmp_opr_digit = tmp_opr_digit >> 1
        oprs.reverse()

        formula = ""
        for i, v in enumerate(oprs):
            formula += str(nums[i]) + str(oprs[i])
        formula += str(nums[-1])
        total += eval(formula)

    return total


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3064
import heapq
 
L1 = input().split(" ")
L2 = input().split(" ")
tickets = int(L1[1])
L2int = [-int(s) for s in L2]
 
heapq.heapify(L2int)
 
for t in range(tickets):
    heapq.heappush(L2int,-(-heapq.heappop(L2int)//2))
print(-sum(L2int))

Measured memory_bytes: 14180
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n; cin >> n;
double sum=0;
vector<double> vec(n);
vector<double> a(n);

  for (int i = 0; i < n; i++) {
      cin >> vec.at(i);
     }

  for (int i = 0; i < n; i++) { 
       a.at(i) = 1/vec.at(i);
}
  for (int i = 0; i < n; i++) { 
        sum += a.at(i);
}
   cout << 1/sum<< endl;
    return 0;
}

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

int main()
{
    string s;
    int k;
    cin >> s >> k;
    set<string> subs;

    for(int i = 1; i <= min(k, (int)s.size()); i++){
        for(int j = 0; j <= s.size()-i; j++){
            subs.insert(s.substr(j,i));
        }
    }

    set<string>::iterator it = subs.begin();
    while(k-- > 1)  it++;
    cout << *it << endl;
    return 0;
}

Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] array = br.readLine().split(" ");
		int n = Integer.parseInt(array[0]);
		int m = Integer.parseInt(array[1]);
		int ret = 0;

		int[] box = new int[n];//n個の箱を作成
		boolean[] red = new boolean[n];//n個の箱分赤いボールが入っている可能性があるかどうかのフラグの入れ物を作成

		for(int i=0;i<n;i++){//箱の中に全て1個のボールを入れる
			box[i] = 1;
		}
		red[0] = true;//1個めの箱に赤いボールが入っているのでtrueにする


		for(int i=0;i<m;i++){//m回の処理分ループ
			array = br.readLine().split(" ");
			int from = Integer.parseInt(array[0])-1;
			int to = Integer.parseInt(array[1])-1;

			if(red[from]){//移動元の箱に赤いボールが入っている可能性があるかチェック
				red[to] = true;//移動元に赤いボールが入っている可能性がある場合は移動先に赤いボールが行く可能性があるのでTrueにする
			}

			box[from] -= 1;//fromの箱からボールを1個除く
			box[to] += 1;//toの箱にボールを1個足す

			if( box[from] == 0 ){//fromの箱のボールの数を確認
				red[from] = false;//fromの箱のボールの数が0個である場合は赤いボールが入っている可能性がなくなるのでfalseにする
			}
		}

		for( boolean flag:red){
			if(flag){
				ret += 1;
			}
		}
		System.out.println(ret);
	}

}


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

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

int main(){

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

    cin>>k;
    cout<<a[k-1]<<endl;

    return 0;
}

Measured memory_bytes: 256
//template---{{{
//Header file---{{{
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
//}}}
using namespace std;

//DEFINE---{{{
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b); i > (a); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
//end.DEFINE---}}}

//end.template ---}}}

int main() {
  int N;
  string W[100];
  int WLen[100];

  cin >> N;

  REP(i, N) {
    cin >> W[i];
    WLen[i] = W[i].size();
  }

  bool judge = true;
  REP(i, N - 1) {
    if (W[i][WLen[i] - 1] != W[i + 1][0]) judge = false;
  }

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      if ((i != j) && W[i] == W[j]) judge = false;
    }
  }

  if (judge) cout << "Yes" << endl;
  else cout << "No" << endl;

  return (0);
}


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

# define ll long long

ll fpb(ll a, ll b){
  return (b == 0) ? a : fpb(b, a%b);
}

ll kpk(ll a, ll b){
  return a / fpb(a,b) * b;
}

bool valid(string S, string T) {
  ll lenS = S.size(), lenT = T.size();
  ll f = fpb(lenS, lenT);
  for(int i=0; i<f; i++){
    if(S[i * lenS/f] != T[i * lenT/f]) return false;
  }
  return true;
}

int main(){
 
  int lenS, lenT;
  string S, T;
  cin >> lenS >> lenT;
  cin >> S >> T;
  
  if(valid(S, T)) cout << kpk(lenS, lenT) << endl;
  else cout << -1 << endl;
  
  return 0;
} 



Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n;
vector<PLL> v;
int main()
{
	cin >>n;
	for (ll i=0;i<=3981;i++) v.push_back(MP(i*i*i*i*i,i));
	for (ll i=0;i<=3981;i++)
	{
		v.push_back(MP(-i*i*i*i*i,-i));
		//if (v.back().Fst==0) cout <<v.back().Snd<<" ##\n";
	}
	sort(v.begin(),v.end());
	for (int i=0;i<v.size();i++)
	{
		ll t=n+v[i].Fst;
		if (lower_bound(v.begin(),v.end(),MP(t,(ll)-1e9))!=v.end() &&
		    lower_bound(v.begin(),v.end(),MP(t,(ll)-1e9))->Fst==t)
		{
			//cout <<t<<" "<<v[i].Fst<<" ##\n";
			cout <<lower_bound(v.begin(),v.end(),MP(t,(ll)-1e9))->Snd<<" "<<v[i].Snd;
			return 0;
		}
	}
	return 0;
} 

Measured memory_bytes: 3728
I, O, _, J, L, _, _ = map(int, input().split())

ans = O * 2

if sum([a % 2 for a in (I, J, L)]) >= 2 and min(I, J, L) >= 1:
    I -= 1
    J -= 1
    L -= 1
    ans += 6

ans += sum([(a // 2) * 4 for a in (I, J, L)])
print(ans // 2)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
     int a,b,c,d,e,f,g,h,i,j;
     vector<int>v;
     vector<pair<int,int> >v1;
     map<int,int>m;map<int,int>::iterator it;
     cin>>a;
     int ar[a];
     for(i=0;i<a;i++)
     {
         cin>>ar[i];
     }
     sort(ar,ar+a);
     int ans =0;

     for(i=0;i<a-1;i++)
     {
         ans+=ar[i+1]-ar[i];
     }
     cout<<ans<<endl;
     return 0;



 }


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

int main(){

    int N;
    cin >>N;

 int res=0;
    for(int i=1;i<N+1;i++){
        string temp=to_string(i);

        if(temp.size()%2==1)res++;
    }

    cout<<res<<endl;


}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define ull unsigned long long

int main(){
    int i,j,k,n,bit,a[16]={},x[16][16]={},y[16][16]={},ans=0,tmp=0;
    scanf("%d",&n);
    for (i=0; i<n; i++) {
        scanf("%d",&a[i]);
        for (j=0; j<a[i]; j++) scanf("%d%d",&x[i][j],&y[i][j]);
    }
    for (bit=0; bit<(1<<n); bit++) {
        tmp=0;
        for (i=0; i<n; i++) {
            if (bit & (1<<i)) {
                for (j=0; j<a[i]; j++){
                    if ((bit & (1<<(x[i][j]-1)))){
                        if (y[i][j]!=1) break;
                    }
                    else{
                        if(y[i][j]!=0) break;
                    }
                }
                if (j!=a[i]) break;
            }
        }
        if (i==n) {
            for (k=0; k<=15; k++) if ((bit>>k) & 1) tmp++;
            if (ans<tmp) ans=tmp;
        }
    }
    printf("%d",ans);
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  std::string s; std::cin >> s;
  int n = s.length();
  s.push_back('$');
  std::vector<int> run_length;
  std::vector<int> pos;
  char prv = '$';
  int tmp = 0;
  for (auto it = s.begin(); it != s.end(); it++) {
    auto c = *it;
    if (prv != c) {
      if (tmp != 0) run_length.push_back(tmp);
      if (prv == 'R') {
        assert(c == 'L');
        auto i = it - s.begin();
        pos.push_back(i - 1);
        pos.push_back(i);
      }
      tmp = 0;
    }
    prv = c;
    tmp++;
  }
  int N = run_length.size();
  assert((int)pos.size() == N);
  assert(N % 2 == 0);
  std::vector<int> ans(n, 0);
  for (int i = 0; i < N; i += 2) {
    auto l = run_length.at(i);
    auto r = run_length.at(i + 1);
    ans.at(pos.at(i)) = (l + 1) / 2 + r / 2;
    ans.at(pos.at(i + 1)) = l / 2 + (r + 1) / 2;
  }
  for (int i = 0; i < n; i++) {
    std::cout << (i > 0 ? " " : "") << ans.at(i);
  }
  std::cout << std::endl;
  return 0;
}

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

ll a, b, n, now;

int main(){
	cin >> a >> b >> n;
	if(b <= n) now = a * (b - 1) / b;
	else now = a * n / b - a * ( n / b);
	cout << now;
	return 0;
}

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


int main()
{
    long long a,b,c,i;
    scanf("%lld %lld %lld",&a,&b,&c);
    for(i = 0;i<c;i++)
    {
        if(i%2 == 0)
        {
            if(a%2 == 0)
            {
                b = b+a/2;
                a = a/2;
                continue;
            }
            if(a%2 == 1)
            {
                a = a-1;
                b = b+a/2;
                a = a/2;
                continue;
            }
        }
        if(i%2 == 1)
        {
            if(b%2 == 0)
            {
               a = a+b/2;
               b = b/2;
               continue;
            }
            if(b%2 == 1)
            {
                b = b-1;
                a = a+b/2;
                b = b/2;
                continue;
            }
        }
        printf("%lld %lld\n",a,b);
    }
    printf("%lld %lld",a,b);
    return 0;
}


Measured memory_bytes: 128
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

bool ask(ll x) {
    printf("? %lld\n", x);
    fflush(stdout);
    char res[2];
    scanf("%s", res);
    if (res[0] == 'Y') return true;
    return false;
}

void answer(ll x) {
    printf("! %lld\n", x);
    fflush(stdout);
    exit(0);
}

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    ll num = 1;
    int k = -1;
    for (int i = 0; i <= 10; i++) {
        if (!ask(num)) {
            k = i;
            break;
        }
        num *= 10;
    }
    if (k == -1) {
        num = 1;
        while (!ask(num + 1)) {
            num *= 10;
        }
        answer(num);
    }
    ll res = 0;
    for (int i = 1; i < k; i++) {
        int left = 0, right = 9;
        while (left < right) {
            int mid = (left + right + 1) / 2;
            if (ask(res * 10 + mid)) {
                left = mid;
            } else {
                right = mid - 1;
            }
        }
        res = res * 10 + left;
    }
    int temp = 0;
    for (int i = 9; i >= 0; i--) {
        if (!ask((res * 10 + i) * 10LL)) {
            temp = i + 1;
            break;
        }
    }
    res = res * 10 + temp;
    answer(res);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 684