akhauriyash/Code-Regression huggingface dataset:
from itertools import product

N=int(input())
data=[]
for i in range(N):
    for j in range(int(input())):
        x,y=map(int,input().split())
        data.append((i,x-1,y)) #iさんがx-1さんに嘘(0)or正直(1)


ans=0
for i in product([0,1],repeat=N):
    ok=True
    for j in data:
        if i[j[0]]==1 and i[j[1]]!=j[2]:
            ok = False
            break
    if ok:
        ans=max(ans,sum(i))
print(ans)

Measured memory_bytes: 9092
#include<bits/stdc++.h>
#define x      first
#define y      second
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pll;

struct data {
   int id; LL x, y;
   data() {}; data(int id, LL x, LL y) : id(id), x(x), y(y) {};
};
struct edge {
   int u, v; LL w;
   edge() {}; edge(int u, int v, LL w) : u(u), v(v), w(w) {};
};

bool cmpX(data a, data b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }
bool cmpY(data a, data b) { return a.y < b.y || (a.y == b.y && a.x < b.x); }
bool cmp(edge a, edge b) { return a.w < b.w; }
LL dis(data a, data b) { return min(abs(a.x - b.x), abs(a.y - b.y)); }

const int N = 1e5 + 4;
int n, par[N];
data a[N];
vector<edge> E;

int root(int v) { return (par[v] < 0) ? v : (par[v] = root(par[v])); }

void kruskal() {
   sort(E.begin(), E.end(), cmp);
   for (int i = 1; i <= n; ++i) par[i] = -1;
   int Count = 0; LL ans = 0;

   for (int i = 0; i < E.size(); ++i) {
      if (Count == n-1) break;

      int u = E[i].u, v = E[i].v;
      if ((u = root(u)) == (v = root(v))) continue;

      if (par[u] > par[v]) swap(u, v);
      par[u] += par[v]; par[v] = u;

      ans += E[i].w; Count++;
   }

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

int main() {
   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   //freopen("nhap.inp", "r", stdin);
   //freopen("nhap.out", "w", stdout);

   cin >> n;
   LL x, y;
   for (int i = 1; i <= n; ++i) {
      cin >> x >> y;
      a[i] = data(i, x, y);
   }

   sort(a+1, a+n+1, cmpX);
   for (int i = 1; i < n; ++i) E.push_back(edge(a[i].id, a[i+1].id, dis(a[i], a[i+1])));

   sort(a+1, a+n+1, cmpY);
   for (int i = 1; i < n; ++i) E.push_back(edge(a[i].id, a[i+1].id, dis(a[i], a[i+1])));

   kruskal();

   return 0;
}


Measured memory_bytes: 8688
#include <stdio.h>
 
int main(void){
  char s[101],p[101];
  int i,j,sn=0,pn=0,t;
 
  scanf("%s %s",s,p);
 
//文字数カウント
  while(s[sn] != '\0') sn++;
  while(p[pn] != '\0') pn++;
 
  for(i=0;i<sn;i++){
    t=1;
    for(j=0;j<pn;j++)
      if(s[(i+j)%sn] != p[j]) t=0;
    if(t) break;
  }
 
  if( t )
    printf("Yes\n");
  else
    printf("No\n");
 
  return 0;
}


Measured memory_bytes: 2144
import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,m=mis()
    ans=n*(n-1)+m*(m-1)
    print(ans//2)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
n, l = map(int, input().split())
taste = []
for i in range(1, n + 1):
    taste.append(l + i - 1)
m = 1000
for i in range(n):
    if abs(taste[i]) < m:
        m = abs(taste[i])
        eat = taste[i]
print(sum(taste) - eat)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<int> a(n);
    int maxe = -1e+7, mine = 1e+7;
    int maxid = -1, minid = -1;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        if(a[i] > maxe){
            maxe = a[i];
            maxid = i;
        }
        if(a[i] < mine){
            mine = a[i];
            minid = i;
        }
    }
    vector<P> ans;
    if(maxe >= abs(mine)){
        for(int i = 0; i < n; ++i){
            if(a[i] < 0){
                a[i] += maxe;
                ans.push_back(P(maxid, i));
            }
        }
        for(int i = 0; i < n - 1; ++i)  ans.push_back(P(i, i + 1));
    }
    else{
        for(int i = 0; i < n; ++i){
            if(a[i] > 0){
                a[i] += mine;
                ans.push_back(P(minid, i));
            }
        }
        for(int i = n - 1; i > 0; --i)  ans.push_back(P(i, i - 1));
    }
    int sz = ans.size();
    cout << sz << endl;
    for(int i = 0; i < sz; ++i) cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
}

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

using namespace std;

int main()
{
	int n;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int c , a , n;
		int ans = 0;

		cin >> c >> a >> n;

		int min1 = min(c , min(a , n));
		c -= min1 , a -= min1 , n -= min1;
		ans += min1;
		
		min1 = min(c / 2 , a);
		c -= (min1 * 2) , a -= min1;
		ans += min1;

		if (c / 3 > 0)
		{
			ans += c / 3;
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> p(n), a(n), b(n);
    rep(i, n) cin >> p[i], p[i]--;
    a[0] = 1;
    rep(i, n-1) a[i+1] = a[i] + 30000;
    rep(i, n) b[i] = a[n-1-i];

    rep(i, n) {
        b[p[i]] += i;
    }
    rep(i, n) cout << a[i] << (i == n-1 ? '\n' : ' ');
    rep(i, n) cout << b[i] << (i == n-1 ? '\n' : ' ');
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
set<int> days;
vector<pii> jobs;
int main() {
    int n,m,a,b,ans=0;
    scanf ("%d %d",&n,&m);
    for (int i = 0; i < n; i++) {
        scanf ("%d %d",&a,&b);
        jobs.emplace_back(a,b);
    }
    for (int i = 0; i < m; i++) days.insert(i);
    sort(jobs.begin(),jobs.end(),[](pii a, pii b) {return a.second > b.second;});
    for (pii p : jobs) {
        auto it = days.upper_bound(m-p.first);
        if (it == days.begin()) continue;
        --it;
        days.erase(it);
        ans += p.second;
    }
    printf ("%d\n",ans);
    return 0;
}


Measured memory_bytes: 5748
i = list(map(int, input().split()))
j = list(map(int, input().split()))
d = 0
x = i[1]
y = i[0]
for i in range(i[0]):
  d = d + j[i] 
  if d > x:
    print(i+1)
    break

if d <= x:
  print(y+1)

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

#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define sortv(v) sort(v.begin(),v.end());
#define sorta(a,n) sort(a,a+n);
#define arrayin(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define arrayout(a,n) for(int i=0;i<n;i++) cout<<" ";cout<<"\n";
#define whatIs(x) cout<<#x<<" is "<<x<<endl;
#define fillA(a,value) memset(a,value,sizeof(a));
#define len(s) s.length()
#define reached cout<<"reached "<<endl;
#define INF INT_MAX //Infinity
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define MOD 1000000007
#define fi first
#define se second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vi64 vector<lli>
#define viii vector<tuple<int,int,int>>
#define prq priority_queue<int>
#define mii map<int,int>
#define msi multiset<int>
#define nl "\n"
#define sii set<int,int>
#define sz size

typedef long long int lli;
typedef unsigned long long int ulli;
typedef double ld;

using namespace std;

int main()
{
	fio;
	/*int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
	}*/
	string s;
	cin>>s;
	int f=0;
	REP(i,len(s)-1)
	{
		if(s[i]=='A' and s[i+1]=='C')
		{
			f=1;
			break;
		}
	}
	if(f) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<limits>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;
namespace Arithmetics {
	template<typename T>
	T original_pow(T a, T b) {
		T ans = 1;
		rep(i, b) {
			ans *= a;
		}

		return  ans;
	}
	template<typename T>
	T gcd(T a, T b) {
		if (a > b) {
			T c = a;
			a = b;
			b = c;
		}
		if (a == 0) {
			return b;
		}

		return gcd(b % a, a);
	}
	template<typename T>
	T gcd_of_all(vector<T> v) {
		T temp = v[0];
		for (T elem : v) {
			temp = gcd(temp, elem);
		}

		return temp;
	}
	template<typename T>
	T lcm(T a, T b) {
		T GCD = gcd(a, b);
		return a * b / GCD;
	}
	template<typename T>
	T lcm_of_all(vector<T> v) {
		T temp = v[0];
		for (T elem : v) {
			temp = lcm(temp, elem);
		}
		return temp;
	}
}
using namespace Arithmetics;
void prob138() {
	int N; cin >> N;
	priority_queue<double,vector<double>,greater<double>> pq;
	for (int i = 0; i < N; i++) {
		double x;
		cin >> x;
		pq.push(x);
	}

	for (int i = 0; i < N - 1; i++) {
		double x = pq.top(); pq.pop();
		double y = pq.top(); pq.pop();
		double z = (x + y) / 2;
		pq.push(z);
	}

	printf("%.10lf\n", pq.top());
}

void prob136() {
	int N; cin >> N;
	int max = 0, min = int_INF;
	bool flag = false;
	rep(i, N) {
		int x; cin >> x;
		if (x > max) {
			max = x; min = int_INF;
		}
		x <= min ? min = x : 1;
		if (max - min > 1) {
			flag = true;
			break;
		}
	}

	if (flag) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

void prob140() {
	int N; cin >> N;
	vector<int> B(N + 1);
	B[0] = int_INF; B[N] = int_INF;
	for (int i = 1; i < N; i++) {
		cin >> B[i];
	}
	ll ans = 0;
	for (int j = 0; j < N; j++) {
		ans += min(B[j], B[j + 1]);
	}

	cout << ans << endl;
}

void prob141() {
	int N, K, Q; cin >> N >> K >> Q;
	vi Contestants(N);
	rep(i, Q) {
		int x;
		cin >> x;
		Contestants[--x]++;
	}

	rep(i, N) {
		if (Contestants[i] + K - Q > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

void prob148() {
	ll a, b;
	cin >> a >> b;
	cout << lcm(a, b) << endl;
}
bool is_prime[100000000 + 1];
vi Eratosthenes(const int N) { // return primes up to N
	vector<int> P;
	for (int i = 0; i <= N; i++)
	{
		is_prime[i] = true;
	}
	for (int i = 2; i <= N; i++)
	{
		if (is_prime[i])
		{
			for (int j = 2 * i; j <= N; j += i)
			{
				is_prime[j] = false;
			}
			P.emplace_back(i);
		}
	}
	return P;
}
void prob149() {
	int x; cin >> x;
	vi Eratos = Eratosthenes(1000003);
	auto iter = lower_bound(Eratos.begin(), Eratos.end(), x);
	int index = distance(Eratos.begin(), iter);
	cout << Eratos[index] << endl;
}

void prob149A() {
	string s, t;
	cin >> s >> t;
	cout << t+s << endl;
}

int main() {
	prob149A();
}

Measured memory_bytes: 256
# import numpy as np
N, M = list(map(int, input().split()))

A = [list(map(int, input().split()))[1:] for _ in range(N)]

cnt = {}
for i in range(1, M+1):
    cnt[i] = 0

for A_row in A:
    for a in A_row:
        cnt[a] += 1
ans = 0
for i in range(1, M+1):
    if N == cnt[i]:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int H, W, K; cin >> H >> W >> K;
  vector<string> S(H);
  for (int row=0;row<H;row++) cin >> S.at(row); 
  
  int ans = 0;

  for (int tmp_r=0;tmp_r<(1<<H);tmp_r++){
    bitset<6> r(tmp_r);
    for (int tmp_c=0;tmp_c<(1<<W);tmp_c++){
      bitset<6> c(tmp_c);
      int totk = 0;
      rep(row,H) rep(col,W) {
        if (r.test(row) || c.test(col)) continue;
        if (S[row][col]=='#') totk++; 
      }
      if (totk==K) ans++;

    }
  }
  cout << ans << endl;
    

  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define N 1000000007
long long int exponentiation(long long int base, 
                        long long int exp) 
{ 
    if (exp == 0) 
        return 1; 
  
    if (exp == 1) 
        return base % N; 
  
    long long int t = exponentiation(base, exp / 2); 
    t = (t * t) % N; 
  
    // if exponent is even value 
    if (exp % 2 == 0) 
        return t; 
  
    // if exponent is odd value 
    else
        return ((base % N) * t) % N; 
} 
int main(){
	long long int mod=1000000007;
	bool is_prime[1000001];
	int spf[1000001];
	for(long int i=2;i<=1000000;i++){
	spf[i]=i;
	is_prime[i]=1;
}
is_prime[0]=0;
is_prime[1]=0;
	for(long int i=2;i*i<=1000000;i++){
		if(is_prime[i]==1){
			for(long int j=i*i;j<=1000000;j+=i){
			spf[j]=i;
			is_prime[j]=0;
		}
		}
	}
	//int spf[1000001];
	long int n;
	cin>>n;
	long int arr[n];
	for(long int i=0;i<n;i++)
	cin>>arr[i];
	long int lcm[1000001];
	for(int i=2;i<=1000000;i++){
		lcm[i]=0;
	}
	set <long int> st;
	for(long int i=0;i<n;i++){
		long int k=arr[i];
		while(k!=1){
			int t=spf[k];
			st.insert(t);
			int count=0;
			while(k%t==0){
				k=k/t;
				count++;
			}
			if(count>lcm[t])
			lcm[t]=count;
		}
	}
	// for(int i=0;i<=3;i++)
	// cout<<i<<" "<<lcm[i]<<endl;
	long long int b[n];
	for(long int i=0;i<n;i++)
	b[i]=1;
	set <long int>::iterator it;
	for(it=st.begin();it!=st.end();it++){
		for(long int j=0;j<n;j++){
			int count=0;
			while(arr[j]%(*it)==0){
				arr[j]=arr[j]/(*it);
				count++;
				}
				b[j]=b[j]*exponentiation(*it,lcm[(*it)]-count);
				b[j]=b[j]%mod;
			}
		}
	long int ans=0;
	for(long int i=0;i<n;i++){
		ans=ans+b[i];
		ans=ans%mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
const char NL = '\n';
const int MOD = 1e9 + 7;
 
void solve()
{
    int k; cin >> k;
    for (int n = 0, i = 1; i <= k; ++i) {
        n = (n * 10 + 7) % k;
        if (n % k == 0) {
        	cout << i << NL;
          	return;
        }
    }
    cout << -1 << NL;
}
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

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

int main(){
  int n,y,m,d,a=0,b=0;
  cin >> n;
  for(int i=1;i<=n;i++){
    cin >> y >> m >> d;
    a=0;
    b=0;
    for(int i=1;i<=999;i++){
      for(int j=1;j<=10;j++){
        if(i%3==0)a+=20;
        else if(j%2==1)a+=20;
        else a+=19;
      }
    }
    for(int i=1;i<=y-1;i++){
      for(int j=1;j<=10;j++){
        if(i%3==0)b+=20;
        else if(j%2==1)b+=20;
        else b+=19;
      }
    }
    for(int i=1;i<=m-1;i++){
        if(y%3==0)b+=20;
        else if(i%2==1)b+=20;
        else b+=19;
    } 
  a+=1;
  b+=d;
  cout << a-b << endl;
  }
}
  
  

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <map>
#define int long long

using namespace std;

typedef long double ld;
typedef pair<int, int> pa;
typedef long long ll;

const int mod = 998244353, N = 1e5;
const ld pi = 3.1415926535;

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

    cout.precision(6);
    cout << fixed;

    int n, m;
    cin >> n >> m;
    int sm = 0;
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        sm += x;
    }
    if (sm > n)
        cout << -1;
    else
        cout << n - sm;
}

Measured memory_bytes: 3640
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int> table,res;
string s,t;
vector<int> pre_kmp(string s){
    vector<int> v(s.size()+1);
    int k;
    v[0]=-1;
    for(int i=1;i<=s.size();i++){
        k=v[i-1];
        while(k>=0){
            if(s[k]==s[i-1])break;
            else k=v[k];
        }
        v[i]=k+1;
    }
    return v;
}
void match(string s, string t){
    int head = 0, j = 0, slen=s.size(),tlen=t.size();
    while(head + j < slen){
        if(t[j] == s[head + j]){
            if(++j != tlen) continue;
            res.push_back(head);
        }
        head += j - table[j], j = max(table[j], 0);
    }
}
int main(void){
    cin>>s>>t;
    table=pre_kmp(t);
    match(s,t);
    for(auto x:res)cout<<x<<endl;
}



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

template<class T>
class SegmentTree {

public:
    /**
     * @param N size
     * @param e identity element
     * @param operation operation for query
     * @param updater operation for update
     */
    SegmentTree(size_t N, T e, function<T(T, T)> operation, function<T(T, T)> updater)
            : e(e), operation(std::move(operation)), updater(move(updater)) {
        n = 1;
        while (n < N) {
            n *= 2;
        }
        data = vector<T>(2 * n - 1, e);
    }

    /**
     * iの値をxに更新
     * @param i index ( 0-indexed )
     * @param x  value
     */
    void update(int i, T x) {
        i += n - 1;
        data[i] = updater(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    /**
     * [a, b)の区間でクエリを実行
     */
    T query(int a, int b) {
        return query(a, b, 0, 0, n);
    }

    /**
     * 添字でアクセス
     * @param i index ( 0-indexed )
     */
    T operator[](int i) {
        return data[i + n - 1];
    }

private:
    int n;
    vector<T> data;
    T e;
    function<T(T, T)> operation;
    function<T(T, T)> updater;

    T query(int a, int b, int k, int l, int r) {
        // 交差しない
        if (r <= a || b <= l) return e;
        // 区間 [a, b) に l, r が含まれる
        if (a <= l && r <= b) return data[k];
        // 左の子
        T c1 = query(a, b, 2 * k + 1, l, (l + r) / 2);
        // 右の子
        T c2 = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return operation(c1, c2);
    }
};

void Main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, pair<int, ll>>> items;
    SegmentTree<ll> segmentTree(N, INF, [](ll a, ll b) { return min(a, b); }, [](ll a, ll b){ return min(a, b); });
    rep(i, M) {
        int l, r;
        ll c;
        cin >> l >> r >> c;
        items.push_back({r, {l, c}});
    }
    sort(items.begin(), items.end());

    vector<ll> dp(N, INF);
    dp[0] = 0;
    segmentTree.update(0, 0);
    rep(i, M) {
        int r = items[i].first;
        int l = items[i].second.first;
        ll c = items[i].second.second;
        l--;
        r--;
        ll x = segmentTree.query(l, r + 1);
        ll tmp = x + c;
        dp[r] = min(dp[r], tmp);
        segmentTree.update(r, tmp);
    }
    if (dp[N - 1] != INF) {
        cout << dp[N - 1] << '\n';
    } else {
        cout << -1 << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 6900
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define mem(x,y)		(x*)malloc(sizeof(x)*(y))

int main(void)
{
	int n;
	while(scanf("%d",&n),n)
	{
		int i,j;
		int* table = mem(int,n);
		for(i = 0;i < n;i++)
		{
			scanf("%d",&table[i]);
			if(i)
				table[i] += table[i-1];
		}
		int max = -1000000000;
		for(i = 0;i < n;i++)
		{
			if(table[i] > max)
				max = table[i];
			for (j = 0; j < i; j += 1)
			{
				if((table[i]-table[j]) > max)
					max = table[i]-table[j];
			}
		}
		printf("%d\n",max);
	}
	return 0;
}

Measured memory_bytes: 0
var
 a:ansistring;
 i,m:longint;
begin
 readln(a);
 for i:=1 to length(a)-2 do
  if (a[i]=a[i+1]) and (a[i]=a[i+2]) and (a[i+1]=a[i+2]) then begin m:=1;break;end;
  if m=1 then writeln('Yes')
         else writeln('No');
end.

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   int a, b, c;
   cin >> a >> b >> c;
   if (a + b >= c) {
      puts("Yes");
   } else {
      puts("No");
   }

   return 0;
}

Measured memory_bytes: 256
pos = {'N':0, 'W':0, 'S':0, 'E':0}

for s in input(): pos[s] += 1
    
ans = 'Yes'

if not (pos['N'] and pos['S'] or not pos['N'] and not pos['S']): ans = 'No'
if not (pos['W'] and pos['E'] or not pos['W'] and not pos['E']): ans = 'No'

print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
#define N 100

int main(void){
	int i,n,j;
	int line[N];
	int area,prearea;

	for(i=0;scanf("%d",&line[i])==1;i++){}
	n=i;
	for(i=0;i<n;i++){
		area=2;
		for(j=1;j<line[i];j++){
			prearea=j+1;
			area+=prearea;
		}
		printf("%d\n",area);
	}
	return 0;
}

Measured memory_bytes: 0
/**
* Think twice, code once.
* 1.integer overflow(maybe even long long overflow : (a+b >= c) -> (a >= c-b)
* 2.runtime error
* 3.boundary condition
* ---------------------------------------------------------------------------------------
* Author : zzy
* Date : 2020-03-28-20.01.26 Saturday
*/
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

i64 x;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> x;
   // cerr <<"yes" << endl;
    i64 ans = 0;
    i64 cnt = x/500;
    ans += cnt*1000;
    x -= cnt*500;
    cnt = x/5;
    ans += cnt*5;
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>

using namespace std;

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

int n;
int a[10][10];
int res[3][12][2];
int ii, jj, kk;
int dy1[] = {-2, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int dx1[] = {0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0};
int dy2[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
int dx2[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int dy3[] = {-1, 0, 0, 0, 1};
int dx3[] = {0, -1, 0, 1, 0};

bool solve(int i, int j, int k, int y, int x) {
  if (y == 10) {
    if (i == 0 && j == 0 && k == 0) {
      rep (t, ii) cout << res[0][t][1] << " " << res[0][t][0] << " 3" << endl;
      rep (t, jj) cout << res[1][t][1] << " " << res[1][t][0] << " 2" << endl;
      rep (t, kk) cout << res[2][t][1] << " " << res[2][t][0] << " 1" << endl;
      return true;
    } else {
      return false;
    }
  }
  if (x == 10) return solve(i, j, k, y + 1, 0);
  if (3 <= y && a[y - 3][x]) return false;
  if (a[y][x] == 0) return solve(i, j, k, y, x + 1);
  if (solve(i, j, k, y, x + 1)) return true;
  if (i > 0 && 2 <= y && y < 8 && 2 <= x && x < 8) {
    rep (t, 13) if (a[y + dy1[t]][x + dx1[t]] == 0) goto fail1;
    res[0][i - 1][0] = y;
    res[0][i - 1][1] = x;
    rep (t, 13) --a[y + dy1[t]][x + dx1[t]];
    if (solve(i - 1, j, k, y, x)) return true;
    rep (t, 13) ++a[y + dy1[t]][x + dx1[t]];
  }
 fail1:;
  if (j > 0 && 1 <= y && y < 9 && 1 <= x && x < 9) {
    rep (t, 9) if (a[y + dy2[t]][x + dx2[t]] == 0) goto fail2;
    res[1][j - 1][0] = y;
    res[1][j - 1][1] = x;
    rep (t, 9) --a[y + dy2[t]][x + dx2[t]];
    if (solve(i, j - 1, k, y, x)) return true;
    rep (t, 9) ++a[y + dy2[t]][x + dx2[t]];
  }
 fail2:;
  if (k > 0 && 1 <= y && y < 9 && 1 <= x && x < 9) {
    rep (t, 5) if (a[y + dy3[t]][x + dx3[t]] == 0) goto fail3;
    res[2][k - 1][0] = y;
    res[2][k - 1][1] = x;
    rep (t, 5) --a[y + dy3[t]][x + dx3[t]];
    if (solve(i, j, k - 1, y, x)) return true;
    rep (t, 5) ++a[y + dy3[t]][x + dx3[t]];
  }
 fail3:;
  return false;
}

int main() {
  cin >> n;
  rep (i, 10) rep (j, 10) cin >> a[i][j];
  int cnt = 0;
  rep (i, 10) rep (j, 10) cnt += a[i][j];
  rep (i, n + 1) rep (j, n + 1) rep (k, n + 1) {
    if (i + j + k != n) continue;
    if (i * 13 + j * 9 + k * 5 != cnt) continue;
    ii = i;
    jj = j;
    kk = k;
    if (solve(i, j, k, 0, 0)) return 0;
  }
}

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

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int64 modpow(int64 a, int64 n, int64 mod) {
    int64 res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    int pop = count(x.begin(), x.end(), '1');
    map<int64, int64> base;
    for (int64 i=0; i<n; i++) {
        base[pop+1] *= 2;
        base[pop-1] *= 2;
        if (x[i] == '1') {
            base[pop+1] += 1;
            base[pop-1] += 1;
        }

        base[pop+1] %= (pop+1);
        if (pop>1) base[pop-1] %= (pop-1);
    }


    reverse(x.begin(), x.end());
    vector<int64> ans;
    for (int64 i=0; i<n; i++) {
        int64 cp;
        int64 sum;

        if (x[i] == '1' && pop == 1) {
            ans.push_back(0);
            continue;
        }

        if (x[i] == '0') {
            cp = pop + 1;
            sum = base[pop+1];
            sum += modpow(2, i, pop+1);
            sum %= pop+1;
        } else {
            cp = pop - 1;
            sum = base[pop-1];
            sum -= modpow(2, i, pop-1);
            if (sum < 0) sum += pop-1;
            sum %= pop-1;
        }

        int64 t = 1;
        while (sum != 0) {
            sum %= __builtin_popcount(sum);
            t++;
        }
        ans.push_back(t);
    }

    reverse(ans.begin(), ans.end());
    for (auto a : ans) cout<<a<<endl;
}

Measured memory_bytes: 5288
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    deque<LL> d(n);
    REP(i,n)cin>>d[i];
    LL ans = 0;
    REP(i,k){
        int deq = k - i;
        int enq = i;
        REP(j, deq+1){
            int left = deq - j;
            int right = j;

            deque<LL> v = d;
            VL have;
            LL sum = 0;

            REP(t, left){
                if(v.empty())break;
                sum += v.front();
                have.PB(v.front());
                v.pop_front();
            }
            REP(t, right){
                if(v.empty())break;
                sum += v.back();
                have.PB(v.back());
                v.pop_back();
            }

            if(!have.empty())SORT(have);

            REP(t, enq){
                if(t > have.size() - 1)break;
                if(have[t] >= 0)break;
                sum -= have[t];
            }

            //cout<<i<<" "<<j<<" "<<sum<<endl;
            ans = max(ans, sum);
        }
    }
    PUTS(ans);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    scanf("%d",&n);
    int buri[2][114514]={};
    for(int i=0;i<n;i++){
        int po;
        scanf("%d",&po);
        buri[i%2][po]++;
    }
    int max[2][2]={};
    for(int i=0;i<114514;i++)for(int j=0;j<=1;j++){
        if(buri[j][max[0][j]]<buri[j][i])max[0][j]=i;
    }
    for(int i=0;i<114514;i++)for(int j=0;j<=1;j++){
        if(buri[j][max[1][j]]<buri[j][i]&&i!=max[0][j])max[1][j]=i;
    }
    if(max[0][0]!=max[0][1])printf("%d",n-buri[0][max[0][0]]-buri[1][max[0][1]]);
    else{
        for(int k=0;k<=1;k++)for(int l=0;l<=1;l++)max[k][l]=buri[l][max[k][l]];
        if(max[0][0]+max[1][1]>max[1][0]+max[0][1])printf("%d",n-max[0][0]-max[1][1]);
        else printf("%d",n-max[1][0]-max[0][1]);
    }
    return 0;
}


Measured memory_bytes: 1152
#include<cstdio>
#include<algorithm>
int n,ans,a[310];
int main()
{
	scanf("%d",&n),n*=2;
	for(register int i=1;i<=n;++i)scanf("%d",&a[i]);
	std::sort(a+1,a+n+1);
	for(register int i=n-1;i>0;i-=2)ans+=a[i];
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	string s; cin >> s;
	bool valid = false;

	rep(i, 0, s.size()) {
		if (s[i] == s[i + 1])
		{
			cout << i + 1 << " " << i + 2 << endl;

			return 0;
		}
	}
	rep(i, 0, s.size() - 1) {
		if (s[i] == s[i + 2] && s[i] != s[i + 1]) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}

	cout << -1 << " " << -1 << endl;

	return 0;
}

Measured memory_bytes: 512
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main(void){
    string n;
    cin >> n;
    for(ll i=0; i<3;i++){
        if( n[i] == '7'){
            cout << "Yes" <<endl;
            break;
        }
        if(i == 2){
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 998244353;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    string s;
    cin >> s;
    int cnt = 0;
    for (char c : s) cnt += c - '0';
    cout << min(cnt, sz(s) - cnt) * 2 << endl;
}


Measured memory_bytes: 512
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    N = I()
    print(pow(N, 3))
    return


# B
def B():
    N = I()
    A = LI()
    B = LI()
    C = LI()
    a_p = -1
    ans = 0
    for a in A:
        if (a - a_p == 1):
            ans += B[a - 1] + C[a - 2]
        else:
            ans += B[a - 1]
        a_p = a
    print(ans)
    return


# C
def C():
    N = I()
    B = LI()
    A = [0 for i in range(N)]
    A[0] = B[0]
    A[N - 1] = B[N - 2]
    for i in range(1, N - 1):
        A[i] = min(B[i - 1], B[i])
    print(sum(A))
    return


# D
def D():
    n,k=LI()
    s=S()
    cnt1=0
    cnt2=0
    i_pre=''
    if(s[0]=='L'):
        cnt1+=1
    if(s[n-1]=='R'):
        cnt1+=1
    for i in s:
        if i_pre=='R' and i=='L':
            cnt2+=1
        i_pre=i
    ans=n-cnt1-2*cnt2
    if cnt1==0:
        if k<=cnt2-1:
            print(ans+2*k)
        else:
            print(n-1)
    if cnt1==1:
        if k<=cnt2:
            print(ans+2*k)
        else:
            print(n-1)
    if cnt1==2:
        if k<=cnt2:
            print(ans+2*k)
        else:
            print(n-1)
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    D()
    return


# Solve
if __name__ == "__main__":
    D()


Measured memory_bytes: 49776
from operator import mul
from functools import reduce

N = int(input())
A = list(map(int,input().split()))

def cmb(n, r):
    if n < r:  return 0
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

dic = {}
ma = max(A)
for i in range(N):
    if A[i] in dic:
        dic[A[i]] += 1
    else:
        dic[A[i]] = 1
        
c = [0 for _ in range(ma + 1)]
for i in dic:
    c[i] = cmb(dic[i], 2)
sum_ = sum(c)

for i in range(N):
    ans = sum_ - c[A[i]] + cmb(dic[A[i]] - 1, 2)
    print(ans)

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

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

    int ans=0;
    for(int i=1; i<n; i++){
        int tmp=0;
        
        for(char c='a'; c<='z'; c++){
            bool left=false, right=false;
            for(int j=0; j<i; j++) if(s[j]==c) left=true;
            for(int j=i; j<n; j++) if(s[j]==c) right=true;

            if(left&&right) tmp++;
        }

        ans=max(ans,tmp);
    }

    cout << ans << endl;
}

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

bool same (string S, string T) {

    bool same;

    for (int i = 0; i < S.size(); i++) {
        same = true;
        for (int j = 0; j < S.size(); j++) {
            if (S[(i + j) % S.size()] != T[j]) {
                same = false;
                break;
            }
        }
        if (same) {
            return true;
        }
    }

    return false;
}

int main () {

    string S, T;

    cin >> S >> T;

    if (same(S, T)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

#define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.fi << ", " << a.se << ')';
    return out;
}
}

int main(){
    int h, w, m;
    cin >> h >> w >> m;
    vi y(m), x(m);
    rep(i, m) {
        cin >> y[i] >> x[i];
        --y[i];
        --x[i];
    }
    using P = pair<int, int>;
    set<P> st;
    rep(i, m) st.emplace(y[i], x[i]);

    vl cy(h), cx(w);
    rep(i, m) {
        cy[y[i]]++;
        cx[x[i]]++;
    }
    ll ma_y = 0, ma_x = 0;
    rep(i, h) chmax(ma_y, cy[i]); 
    rep(i, w) chmax(ma_x, cx[i]);

    vi usedy(h), usedx(w);
    rep(i, h) if(ma_y == cy[i]) usedy[i] = 1;
    rep(i, w) if(ma_x == cx[i]) usedx[i] = 1;

    ll ans = ma_y + ma_x;

    ll cnt = 0;
    rep(i, m) {
        if(usedy[y[i]] && usedx[x[i]]) cnt++;
    }        
    if(cnt == accumulate(all(usedy), 0LL) *accumulate(all(usedx), 0LL)) {
        ans--;
    }
    cout << ans << '\n';
    // cout << ma_x << " " << ma_y << '\n';
    // dumpVL(cy);
    // dumpVL(cx);
    return 0;
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    priority_queue<double> prices;
    for (int i = 0; i < N; i++)
    {
        int price;
        cin >> price;
        prices.push(price);
    }
    for (int i = 0; i < M; i++)
    {
        double price = prices.top();
        prices.pop();
        prices.push(price / 2.0);
    }
    long sum = 0;
    for (int i = 0; i < N; i++)
    {
        double price = prices.top();
        prices.pop();
        sum += (long)price;
    }
    cout << sum << endl;
}


Measured memory_bytes: 1400
/**
*    author:  souzai32
*    created: 13.08.2020 10:05:23
**/

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

int main() {

    long long n,k;
    cin >> n >> k; 
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);

    long long ans=0, count=0, num;
    rep(i,n-1){
        for(int j=n-1; j>i; j--) if(a.at(i)>a.at(j)) ans++;
    }
    ans*=k;
    ans%=long(1e9+7);
    
    sort(a.begin(),a.end(),greater<>());
    long long b=n*(n-1)/2;
    rep(i,n-1){
        if(a.at(i)==a.at(i+1)) count++;
        else count=0;
        b-=count;
        // cout << count << endl;
    }
    // cout << b << endl;
    if(k%2){
        b*=k;
        b%=long(1e9+7);
        b*=(k-1)/2;
        b%=long(1e9+7);
    }
    else{
        b*=k/2;
        b%=long(1e9+7);
        b*=k-1;
        b%=long(1e9+7);
    }
    ans+=b;
    ans%=long(1e9+7);
    // cout << b << endl;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  int N;
  string s, t;
  cin >> N >> s >> t;

  for (int i = 0; i < N; i++) {
    cout << s[i] << t[i];
  }

  cout << endl;

  return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    // 和がx以上になるペアの個数がM以下か
    auto check = [&](ll x) {
        ll total = 0;
        rep(i, N) total += A.end() - lower_bound(A.begin(), A.end(), x - A[i]);
        return total <= M;
    };

    ll ng = 0, ok = 2 * A[N - 1] + 1;
    while (ok - ng > 1) {
        ll mid = (ng + ok) / 2;
        if (check(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    vector<ll> s(N + 1);
    rep(i, N) s[i + 1] = s[i] + A[i];

    ll ans = 0, cnt = 0;
    rep (i, N) {
        int d = lower_bound(A.begin(), A.end(), ok - A[i]) - A.begin();
        cnt += N - d;
        ans += (s[N] - s[d]) + (N - d) * A[i]; //iと[d～N)までの要素のペアをカウントする
    }
    ans += ng * (M - cnt);

    cout << ans << endl;
}

Measured memory_bytes: 1920
program sample
    implicit none
  
    integer(8) :: i,j,m,n,k,b,c,d
    integer(8),allocatable :: a(:),y(:)
  
    read(*,*) n,k
    allocate(a(n),y(n))
    read(*,*)a
    y(:)=0
    do i=1,n
        b=a(i)
        y(b)=y(b)+1
    end do
    call msort(y)
    c=0
    do i=1,n-k
        c=c+y(i)
    end do
        
    write(*,*) c
  
    stop
    contains
    recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)
 
    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if
 
    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))
 
    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x
 
    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do
 
    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n
 
    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort
end program sample
  



Measured memory_bytes: 8496