akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        String T = scan.next();
        boolean answer = solve(S, T);
        System.out.println(answer ? "Yes" : "No");
    }
    private static boolean solve(String S, String T) {
        String double_S = S + S;
        return double_S.indexOf(T) >= 0;
    }
}


Measured memory_bytes: 21972
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <random>
#include <chrono>
using namespace std;

int k, n;
const int maxn = 2e5 + 5;
int a[maxn];

int main(){
    cin >> k >> n;
    int ans = 0;
    for(int i = 0;i < n;i++){
        scanf("%d", &a[i]);
    }
    for(int i = 0;i < n;i++){
        if(i < n - 1){
            ans = max(ans, a[i + 1] - a[i]);
        }else{
            ans = max(ans, a[0] + k - a[i]);
        }
    }
    cout << k - ans << endl;
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
using namespace std;
typedef long long int ll;


//再帰的な方法で解く。メモ化していないのでTLEになるはず。
int N;
int h[100010]; //N <= 10^5なのでその分だけ用意しておく。
ll dp[100010]; //メモ化回帰用
const long long INF = 1LL << 60;
  
void chmin(ll& a, ll b){
  if (a > b){
    a = b;
  }
}

ll rec(int i){
  ll res = INF;
  
  //すでに計算されていたら枝を作らずにリターンする
  if (dp[i] < INF) return dp[i];
  
  //ベースケース
  if (i == 0){
    return 0;
  }

  //i-1から来た時(枝その１)
  chmin(res, rec(i-1) + abs(h[i] - h[i-1]));
  //i-2から来た時(枝その２)
  if(i > 1) chmin(res, rec(i-2) + abs(h[i] - h[i-2]));
  
  return dp[i] = res;
}

int main(){
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> h[i];
  }
  
  // 初期化 (最小化問題なので INF に初期化)
  for (int i = 0; i < 100010; i++) dp[i] = INF;
  //初期条件
  dp[0] = 0;

  cout << rec(N-1);
  
  return 0;
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
#define INF 1e18
using namespace std;

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

class UnionFind{
private:
    vector<int> parent,num;
public:
    UnionFind(int n){
    parent.resize(n); num.resize(n);
	REP(i,n){
	    parent[i]=i; num[i]=1;
	}
    }
    int find(int x){
	if(parent[x]==x) return x;
	return parent[x]=find(parent[x]);
    }
    void unite(int x,int y){
	x=find(x),y=find(y); if(x==y) return;
	if(num[x]<num[y]) swap(x,y);
	parent[y]=x; num[x]+=num[y];
    }

    bool same(int x,int y){
	return find(x)==find(y);
    }
    int size(int x){
	return num[find(x)];
    }
};

signed main()
{
    int N,Q; cin>>N>>Q;
    UnionFind tree(N);
    REP(i,Q){
	int q,x,y; cin>>q>>x>>y;
	if(q==0){
	    tree.unite(x,y);
	}else{
	    cout<<tree.same(x,y)<<endl;
	}
    }	
    
}



Measured memory_bytes: 3244
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7);
	static long cf = 998244353;
    static final int MAX = (int) 1e6;
    public static List<Integer>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fac,inv;
    public  static int[] prime; 
    public static long[] dp;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		int r = sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();
		for(int i=0;i<10;++i) {
			x = r*x-d;
			out.println(x);
		}
		out.close();
	}
	
	
}

Measured memory_bytes: 21076
#include<bits/stdc++.h>
#define ll long long
#define vll vector <long long>
#define pi 2*acos(0.0)
using namespace std;
const int mod =  1000000007;


void solve(){
    int x;
    cin>>x;
    int sum =0;
    int arr[x];
    for(int i = 0;i<x;i++) cin>>arr[i];
    for(int i = 0;i<x;i++){
        for(int j = i+1;j<x;j++){
            sum+= (arr[i]*arr[j]);
        }
    }
    cout<<sum<<endl;


}

int main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}




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

using namespace std;
#define rep(i, N) for(int i=0;i<int(N);++i)
#define rep1(i, N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << "{" << p.first << ", " << p.second << "}";
    return os;
}

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

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

const int INF = (ll) 1e9;
const ll INFLL = (ll) 1e18 + 1;
const ll MOD = (ll) 1e9 + 7;
const double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

ll dp[2020][2020];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vector<ll> A(N);
    vector<l_l> v;
    rep(i, N) {
        cin >> A[i];
        v.emplace_back(A[i], i);
    }
    sort(v.rbegin(), v.rend());
    rep(i, N+1)rep(j, N+1)dp[i][j] = -INFLL;
    dp[0][0] = 0;
    //dp[i][l] := i個目までみて、左にj個入れてるときの最大値
    rep(i, N) {
        rep(l, N) {
            if (i < l)continue;
            ll a = v[i].first;
            ll idx = v[i].second;
            ll r = i - l;
            chmax(dp[i + 1][l + 1], dp[i][l] + a * abs(idx - l));
            chmax(dp[i + 1][l], dp[i][l] + a * abs(idx - (N  - r - 1)));
        }
    }
    ll ans = -INFLL;
    rep(i, N + 1)chmax(ans, dp[N][i]);
    cout << ans << endl;
    /*
    rep(i, N + 1) {
        rep(j, N + 1) {
            cout << ((dp[i][j] == -INFLL) ? -1 : dp[i][j]) << " ";
        }
        cout << endl;
    }*/
}

/*
貪欲は無理
ある程度の貪欲性が必要な処理かな？
O(N^2)はかけてよい。
1 3 4 2

1 -> 3 -> 1
2 -> 4 -> 2
*/

Measured memory_bytes: 35320
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <utility>
#include <map>
#include <functional>
#include <initializer_list>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll kaizyo(ll k, ll l, ll MOD){
    ll sum=1;
    for(ll i=l; i<=k; i++){
        sum *= i;
        sum = sum%MOD;
        }
    return sum;
    }


ll ans(ll a, ll b){
    ll MOD = 1e9+7;
    ll x, y;
    x = kaizyo(a+b, b+1, MOD);
    y = kaizyo(a, 1, MOD);
    return x * modinv(y, MOD) %MOD;
    }

int main(){
    ll X, Y;
    cin >> X >> Y;
    if((2*X-Y)%3!=0 || (2*Y-X)%3!=0 || (2*X -  Y) <0 || (2*Y-X) <0) cout << 0;
    else{
        cout << ans((2*X-Y)/3, (2*Y-X)/3);
        }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
    string ans,S,T;
    int tl,sl,k;
    bool flag = false;
    cin >> S >> T;
    tl = T.length();//Tのながさ
    sl = S.length();//Sのながさ
    if(tl>sl){
        cout << "UNRESTORABLE" << endl;
    }else{
        for(int i=0;i<sl-tl+1;i++){
        string X = S.substr(i, tl);//i番目以降tl文字を抽出して得られる文字列
        int j=0;
        while(j<tl){
            if (X[j]==T[j] || X[j]== '?'){
                j++;
            }
            else
            {
                break;
            }
        }
        if(j==tl){
            flag = true;
            k = i;
            //S.replace(i, tl, T); //i番目以降k文字を文字列tで置換する．tを空文字列にすれば削除の動作
            //break;
        }
    }
    if(flag){
        S.replace(k, tl, T); 
        for(int i=0;i<sl;i++){
            if(S[i]=='?'){
                S.replace(i, 1, "a");
            }
        }
        ans = S;
    }else{
        ans = "UNRESTORABLE";
    }
    cout << ans << endl;
    }
    
}

Measured memory_bytes: 256
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define re register
#define rep(i,s,t) for(re int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(re int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define pt(x) putchar(x)
#define pti(x) printf("%d",x)
#define ptll(x) printf("%lld",x)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
using namespace std;
il int ci(){
	re char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	re int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}
int main(){
	int x1=ci(), x2=ci(), x3=ci();
	if( x1+x2+x3>=22 ) puts("bust");
	else puts("win");
	return 0;
}


Measured memory_bytes: 128
S = input()

S_list = list(S)

answer = []
for S_num in S_list:
    if S_num == '0':
        answer.append('0')
    elif S_num == '1':
        answer.append('1')
    elif not answer:
        continue
    else:
        del answer[-1]

answer_honmono = ''
answer_honmono = ''.join(answer)
print(answer_honmono)

Measured memory_bytes: 3060
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int D = scanner.nextInt();
    int X = scanner.nextInt();
    int tot = X;
    for (int i = 0; i < N; i++) {
      int A = scanner.nextInt();
      tot += (D + A - 1) / A;
    }
    System.out.println(tot);
  }
}


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

int main() {
  using i64 = long long;

  int n;
  std::cin >> n;

  std::map<i64, i64> mp({{0, 1}});
  i64 ans = 0, acc = 0;
  while (n--) {
    i64 a;
    std::cin >> a;
    ans += mp[acc += a]++;
  }
  
  std::cout << ans << std::endl;
  return 0;
}


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

int main() {
    string s;
    int k,i;
    cin>>s;
    cin>>k;
    set<pair<string,int> > sett;
    set<string> trash;
    int n=s.size();
    for(i=0;i<n;i++){
        sett.insert({s.substr(i,1),i});
    }
    
    pair<string,int> p;
    string x;
    int y;
    
    while(k>0){
        
        p=*sett.begin();
        
        sett.erase(*sett.begin());
        x=p.first;
        if(trash.find(x)!=trash.end() )  k++;
        
        else trash.insert(x);

        y=p.second;
        if(y<n-1){
        x+=s[y+1];
        sett.insert({x,y+1});
        }
        k--;
    }
    
    
    cout<<p.first;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
 
using namespace std;
 
int n;
int a,b;
long long arr[55];
long long nck[55][55];
 
int main()
{
	cin >> n >> a >> b;
	assert(a<=b);
	for(int i=0;i<n;i++) cin >> arr[i];
	sort(arr,arr+n);
	long double ans=0;
	for(int i=0;i<a;i++)
		ans+=arr[n-i-1];
	cout << fixed << setprecision(10) << ans/a << endl;
	for(int i=0;i<=n;i++)
	{
		nck[i][0]=1;
		for(int j=1;j<=i;j++) nck[i][j]=nck[i-1][j-1]+nck[i-1][j];
	}
	int comn=0,comnt=0;
	for(int i=n-a;i<n;i++)
	{
		comn+=arr[i]==arr[n-a];
	}
	for(int i=0;i<n;i++)
		comnt+=arr[i]==arr[n-a];
	if(arr[n-a]==arr[n-1])
	{
		long long ans=0;
		for(int i=a;i<=min(b,comnt);i++)
			ans+=nck[comnt][i];
		cout << ans << endl;
		return 0;
	}
	//cout << comn << " " << comnt << endl;
	cout << nck[comnt][comn] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
//orz hxr
#define ll long long
#define ull unsigned ll
string s;
int main() {
	cin>>s;
	int n=s.length();
	int ans=n;
	for (char c='a'; c<='z'; c++) {
		int last=-1, now=0;
		for (int i=0; i<n; i++) {
			if (s[i]!=c)
				continue;
			now=max(now, i-last-1);
			last=i;
		}
		now=max(now, n-last-1);
		ans=min(ans, now);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut a = s.trim().chars().map(|e| if e == 'B' { 0 } else { 1 });
    let mut ans = 0;
    let mut pre = a.next().unwrap();

    for e in a {
        ans += if e != pre {
            pre = e;
            1
        } else {
            0
        };
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

int main() {
    int N, M;
    while (cin >> N >> M, N) {
        vector<pair<int,int> > v(N);
        int D, P, res = 0;
        for (int i=0; i<N; ++i) {
            cin >> D >> P;
            res += D * P;
            v[i] = make_pair(P, D);
        }
        sort(v.begin(), v.end(), greater<pair<int,int> >());
        for (int i=0; i<N; ++i) {
            if (v[i].second < M) {
                res -= v[i].first * v[i].second;
                M -= v[i].second;
            } else {
                res -= v[i].first * M;
                M = 0;
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1276
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define LL long long
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	int N, K;
	cin >> N >> K;
	
	vector<int> A(N);
	rep(i, N) cin >> A[i];

	map<int, int> dict;
	rep(i, N) dict[A[i]]++;

	vector<int> ball;
	for (auto &kv:dict) {
		ball.push_back(kv.second);
	}
	sort(ALL(ball));

	int ans = 0;
	for (int i = 0; i < int(ball.size()) - K; i++)
	{
		ans += ball[i];
	}

	cout << ans << endl;
	return 0;
}


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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int x,y;
  x = a + b;
  y = c + d;
  if(x > y) puts("Left");
  else if(x < y) puts("Right");
  else puts("Balanced");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main(void) {
    
    
    char a,b;
    cin>>a>>b;
    if(a==b)fin('H');
    else fin('D');
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
   
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define vi vector<int>
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define mod 1000000007
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long

   
 


void solve()
{
  string s;
  cin>>s;
  int sum=0;
  for(auto x:s)sum+=(x-'0');
  if(sum%9)cout<<"No";
  else cout<<"Yes";
}

int32_t main()
{
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    
	int t=1;
//	cin>>t;
	while(t--)solve();
	    
   
}


Measured memory_bytes: 3772
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 2500;
const int K = 19;
int n, q;
int mod = 998244353;
int a[N][N], f[N], invf[N], used[N];
vector < pair < int, int > > v;
int binpow(int x, int y){
    if (y == 0) return 1;
    if (y % 2) return x * binpow(x, y - 1) % mod;
    int z = binpow(x, y / 2);
    return z * z % mod;
}
int c(int n, int k){
    if (k < 0) return 0;
    return f[n] * invf[k] % mod * invf[n - k] % mod;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    set < pair < pair < int, int >, int > > s;
    for (int i = 1; i <= n; i++){
        int x, y;
        cin >> x >> y;
        s.insert({{-x - y, -x}, i});
    }
    int ans = 0;
    for (int i = 1; i <= n; i++){
        auto x = *s.begin();
        if (i % 2) ans = ans - x.F.S; else ans = ans + x.F.F - x.F.S;
        s.erase(x);
    }
    cout << ans;
}


Measured memory_bytes: 6656
package main

import (
	"fmt"
)

func main() {
	var a,b,k int
	fmt.Scan(&a,&b,&k)
	
	for i := a; i <= min(a+k-1, b); i++ {
		fmt.Println(i)
	}
	for i := max(b-(k-1),a+k); i <= b; i++ {
		fmt.Println(i)
	}

}

func min(a,b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a,b int) int {
	if a < b {
		return b
	}
	return a
}

Measured memory_bytes: 512
import collections

k = int(input())
time = 1

q = collections.deque()

q.extend([1,2,3,4,5,6,7,8,9])

while(time <= k):

    i = q.popleft()
    #print(i)
    time += 1

    #0じゃないなら
    if i % 10 != 0:
        q.append(i*10 + i%10 - 1)

    #それ以外
    q.append(i*10 + i%10)

    #9じゃないなら
    if i % 10 != 9:
        q.append(i*10 + i%10 + 1)

print(i)


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

#define REP( i, n) for( int i = 0; i < (n); ++i)
#define FOR( i, a, b) for( int i = (a); i < (b); ++i)

#define pb push_back

const int INF = 100100100;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

int main(){
  
  set<int> s;
  string str;

  cin >> str;
  REP( i, str.size()){
    s.insert((int)str[i]);
  }
  auto itr = s.begin();
  FOR( i, 'a', 'z'+1){
    if( *itr != i ){
      cout << (char)i << endl;
      return 0;
    }
    ++itr;
  }
  cout << "None" << endl;
  return 0;

}


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

void solve(long long N, std::vector<long long> A) {
  map<ll, ll> m;
  for (int i = 0; i < N; i++) {
    m[A[i]]++;
  }
  ll carry = 0;
  ll cardsConsumed = 0;
  for (auto &e : m) {
    ll num = e.first;
    ll count = e.second-1;
    if (carry and count) {
      count--;
      carry--;
    }
    ll numOps = (count / 2) + (count % 2 ? 1 : 0);
    cardsConsumed += numOps*2;
    if (count%2 == 1) {
      carry++;
    }
  }
  cout << A.size() - cardsConsumed << endl;
}

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

  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


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

typedef long long ll;

ll s, c;
ll ans;

int main()
{
	scanf("%lld%lld", &s, &c);
	ans = ((c >> 1) < s) ? (c >> 1) : s + ((c - (s << 1)) >> 2);
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
priority_queue<ll>q;

int main()
{
    ll i,n,m,a;
    scanf("%lld %lld",&n,&m);
    for(i=0; i<n; i++)
    {
        scanf("%lld",&a);
        q.push(a);
    }
    while(m>0 && !q.empty())
    {
        a=q.top();
        q.pop();
        if(a>0)
        {
            q.push(a>>1);
            m--;
        }
    }
    a=0;
    while(!q.empty())
    {
        a+=q.top();
        q.pop();
    }
    cout<<a<<endl;
    return 0;
}


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

using namespace std;

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

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

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

ll ans = 1;
int n;
string s , t;

int main(){
    migmig
    cin >> n;
    cin >> s >> t;
	int i = 0;
	int prev = 0;
	for(; i < n ; i ++){
		int cur = (s[i] == t[i]);
		if(cur){
			if(prev == 0){
				ans*=3;
				ans%=mod;
			}
			if(prev == 1){
				ans = (ans + ans)%mod;
			}
			prev = 1;
		}
		else{
			if(prev == 0){
				ans*=6;
				ans%=mod;
			}
			if(prev == 1){
				ans = (ans + ans)%mod;
			}
			if(prev == 2){
				ans = ans*3 %mod;
			}
			prev = 2;
			i++;
		}
	}
    
    cout << ans << endl;
    
    return(0);
}

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

int main() {
 int a,b,c;
 cin>>a>>b>>c;
 if(a==b){
     if(a==c){
         cout<<"No"; return 0;
     }
     else{
         cout<<"Yes"; return 0;
     }
 }
 
 if(a==c){
     if(a==b){
         cout<<"No"; return 0;
     }
     else{
         cout<<"Yes"; return 0;
     }
 }
 if(b==c){
     if(a==b){
         cout<<"No"; return 0;
     }
     else{
         cout<<"Yes"; return 0;
     }
     
 }
 
 cout<<"No";
 
  return 0;
}

Measured memory_bytes: 256
S = input()

abet = {}
for c in S:
    if c not in abet:
        abet[c] = 1
    else:
        abet[c] += 1

# ４文字の大文字で、２回ずつ存在するなら、辞書の長さは必ず２となるはず
if len(abet.values()) == 2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()

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

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9052
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <numeric>
#include <iterator>
#include <fstream>

using namespace std;

class DMazeMaster {
public:
    int bfs(int x, int y) {
        queue<pair<int, int>> q;
        q.push(make_pair(x, y));
        int cost = 0;
        distance[x][y] = cost;
        visited[x][y] = true;
        while (!q.empty()) {
            auto p = q.front();
            q.pop();
            x = p.first;
            y = p.second;
            cost = distance[x][y] + 1;
            for (const auto &next: move) {
                int moved_x = x + next.first;
                int moved_y = y + next.second;
                if (moved_x < 0 || moved_x >= h || moved_y < 0 || moved_y >= w) {
                    continue;
                } else if (maze[moved_x][moved_y] == '#') {
                    continue;
                }
                if (visited[moved_x][moved_y])continue;
                distance[moved_x][moved_y] = cost;
                visited[moved_x][moved_y] = true;
                q.push(make_pair(moved_x, moved_y));
            }
        }
        int ret = 0;
        for (const auto &item : distance) {
            for (const auto &item2 : item) {
                ret = max(item2, ret);
            }
        }
        return ret;
    }

    void solve(std::istream &cin, std::ostream &cout) {
        cin >> h >> w;
        maze.resize(h);
        for (int i = 0; i < h; ++i) {
            cin >> maze[i];
        }
        move.emplace_back(1, 0);
        move.emplace_back(-1, 0);
        move.emplace_back(0, 1);
        move.emplace_back(0, -1);
        int ans = 0;
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                if (maze[i][j] == '#') continue;
                distance.clear();
                distance.resize(h, vector<int>(w, -1));
                visited.clear();
                visited.resize(h, vector<bool>(w, false));
                ans = max(ans, bfs(i, j));
            }
        }
        cout << ans << endl;
    }

    int h, w;
    vector<string> maze;
    vector<vector<int>> distance;
    vector<vector<bool>> visited;
    vector<pair<int, int>> move;
};


int main() {
    DMazeMaster solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

using namespace std;
;
static const double EPS = 0.0000001;

class Point{
    public :
        double x, y;
        Point(double x = 0, double y = 0):x(x),y(y){}

        Point operator + (Point p) { return Point(x + p.x, y + p.y); }
        Point operator - (Point p) { return Point(x - p.x, y - p.y); }
        Point operator * (double a) { return Point(a * x, a * y); }
        Point operator/(double a) { return Point(x / a, y / a); }

        double dot(Point a) { return a.x * x + a.y * y; }
        double cross(Point a) { return x * a.y - y * a.x; }
        double abs() { return sqrt(norm()); }
        double norm() { return dot(*this); }


};

int main()
{
    double sum = 0;
    int n;
    cin >> n;
    vector<Point> v(n);
    vector<int> num(n);
    for (int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        v[i] = Point(x, y);
        num[i] = i;
    }
    int factrial=1;

    for (int i = 1; i < n+1; i++)
    {
        factrial *= i;
    }

    do
    {
        
        for (int i = 1; i < n; i++)
        {
            Point p = v[num[i]] - v[num[i-1]];
            sum += p.abs();
        }

    } while (next_permutation(num.begin(), num.end()));

    cout << fixed << setprecision(10) << sum/(double)factrial  << endl;
}

Measured memory_bytes: 256
n = int(input())
s = []
for i in range(n):
  s.append(int(input()))
ans = sum(s)
if ans % 10 == 0:
  s.sort()
  f = 0
  for i in range(n):
    if s[i] % 10 == 0:
      next
    else:
      ans -= s[i]
      f = 1
      break
  if f == 0:
    ans = 0
print(ans)

Measured memory_bytes: 3060
gets
NS = gets.split.map(&:to_i)
highs, lows = NS.partition{|n| n >= 3200}
nl = lows.map{|n| n / 400}.uniq.size
nh = highs.size
min = (nl == 0 ? 1 : nl)
max = nl + nh
puts "#{min} #{max}"



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

using namespace std;

int main(void){
    int N, M;
    cin >> N >> M;
    vector<int> g(N + 2);
    for(int i = 0; i < M; i++){
        int L, R;
        cin >> L >> R;
        g[L]++;
        g[R + 1]--;
    }
    int ans = 0;
    if(g[0] == M) ans++;
    for(int i = 1; i <= N; i++){
        g[i] += g[i - 1];
        if(g[i] == M) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC171
{
    class Program
    {
        static void Main(string[] args)
        {
            c();
        }

        public static void c()
        {
            long n = long.Parse(Console.ReadLine());
            string ans = "";

            while (true)
            {
                
                if(n < 27)
                {
                    
                    char c = (char)(96 + n);
                    ans += c;
                    n -= 26;
                }
                else if (n % 26 != 0)
                {
                    
                    long kari = n % 26;
                    char c = (char)(96 + kari);
                    ans += c;
                    n /= 26;
                    
                }
                else if( n % 26 == 0)
                {
                    ans += "z";
                    n /= 26;
                    n--;
                }
                if (n <= 0)
                    break;
            }
            string ans1 = new string(ans.Reverse().ToArray());
            Console.WriteLine(ans1);
        }      
        //1000000000000001
        //  999999999999999
        //  200000000000000
        //  300000000000000
        //  400000000000000
        //  500000000000000
        //  600000000000000
        //  650000000000000
        //  700000000000000
        //  800000000000000
        //  900000000000000
    }
}


Measured memory_bytes: 28236
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long lint;


int main(){
   string s;
   cin >> s;
   
   int ans;
   if(s=="SUN"){
      ans = 7;
   }else if(s=="MON"){
      ans = 6;
   }else if(s=="TUE"){
      ans = 5;
   }else if(s=="WED"){
      ans = 4;
   }else if(s=="THU"){
      ans = 3;
   }else if(s=="FRI"){
      ans = 2;
   }else if(s=="SAT"){
      ans = 1;
   }
   
   cout << ans << endl;
   
   
   
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; 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 COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
ll dp[2010][2010];

//union-find木について
ll par[101010];
ll rank2[101010];
ll usize[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
		usize[i] = 1;
	}
}

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

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (usize[x] < usize[y]) {
		par[x] = y;
		usize[y] += usize[x];
	}
	else {
		par[y] = x;
		usize[x] += usize[y];
	}
}


//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll>a(m), b(m);
	ll ans = 0;
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}
	rep(i, m) {
		init(n);
		rep(j, m) {
			if (i == j)continue;
			unite(a[j], b[j]);
		}
		if (find(a[i]) != find(b[i]))ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(void)
{
	double x1, x2, x3;
	double y1, y2, y3;
	double a1, a2, b1, b2, c1, c2;
	double a, b, c;
	double x, y, r;
	int n;
	int i;
	
	
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
		a1 = 2 * (x2 - x1);
		b1 = 2 * (y2 - y1);
		c1 = pow(x1, 2) - pow(x2, 2) + pow(y1, 2) - pow(y2, 2);
		a2 = 2 * (x3 - x1);
		b2 = 2 * (y3 - y1);
		c2 = pow(x1, 2) - pow(x3, 2) + pow(y1, 2) - pow(y3, 2);
		
		a = sqrt(fabs(x2 - x3) + fabs(y2 - y3));
		b = sqrt(fabs(x3 - x1) + fabs(y3 - y1));
		c = sqrt(fabs(x1 - x2) + fabs(y1 - y2));
		
		x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
		y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
		
		r = sqrt(pow(fabs(x1 - x), 2) + pow(fabs(y1 - y), 2));
		
		printf("%.3lf %.3lf %.3lf\n", x, y, r);
	}
	
	return (0);
}

Measured memory_bytes: 656
#AとBの最大公約数を素因数分解してから考える。
from fractions import gcd
a,b = map(int,input().split())
g = gcd(a,b)
#gを素因数分解し、素因数のセットを作る。
s = set([1])
for i in range(2,int(-(-g**0.5//1)+1)):
  flag = True
  while flag:
    if g%i==0:
      s.add(i)
      g=g//i
    else:
      flag = False
s.add(g)
print(len(s))

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> a(H, vector<char>(W));
    int i,j;
    vector<bool> b(H);
    vector<bool> c(W);

    for(i=0; i<H; i++){
        for(j=0; j<W; j++){
            cin >> a.at(i).at(j);
        }
    }

    for(i=0; i<H; i++){
        for(j=0; j<W; j++){
            if(a.at(i).at(j)=='#'){
                b.at(i)=true;
                c.at(j)=true;
            }
        }
    }

    for(i=0; i<H; i++){
        if(b.at(i)){
            for(j=0; j<W; j++){
                if(c.at(j)) cout << a.at(i).at(j);
            }
            cout << endl;
        }
    }

    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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 (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll dp[3][3];
    bool check[3][3];

    REP(i, 3)REP(j, 3) cin >> dp[i][j];
    REP(i, 3)REP(j, 3) check[i][j] = false;

    ll N;
    cin >> N;
    while(N--){
    	ll b;
    	cin >> b;
    	REP(i, 3)REP(j, 3) if(dp[i][j] == b) check[i][j] = true;
    }

    bool ok = false;

    REP(i, 3){
    	REP(j, 3){
    		cerr << check[i][j] << " ";
    	}
    	cerr << endl;
    }

    REP(i, 3){
    	bool tmp = true;
    	REP(j, 3){
    		if(!check[i][j]) tmp = false;
    	}
    	if(tmp) ok = true;
    }

    dump(ok)

    REP(j, 3){
    	bool tmp = true;
    	REP(i, 3){
    		if(!check[i][j]) tmp = false;
    	}
    	if(tmp) ok = true;
    }
    dump(ok)

    bool tmp = true;
    REP(i, 3){
    	if(!check[i][i]) tmp = false;
    }
    if(tmp) ok = true;
    dump(ok)

    tmp = true;
    REP(i, 3){
    	if(!check[i][2-i]) tmp = false;
    }
    if(tmp) ok = true;

    cout << (ok?"Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
n = int(input())
l = list(map(int,input().split()))
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i] != l[j]:
                if l[i] != l[k]:
                    if l[j] != l[k]:
                        if (l[i] + l[j]) > l[k] and (l[j] + l[k]) > l[i] and (l[k] + l[i]) > l[j]:
                            cnt += 1
print(cnt)

Measured memory_bytes: 9212
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;


namespace AtCoder
{
    class Program
    {
        static long[] Sarray() { return ReadLine().Trim().Split().Select(long.Parse).ToArray(); }
        static List<long> Slist() { return ReadLine().Trim().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            var S = ReadLine();
            long revnum = 0;
            long point = 0;
            for (var i = 0; i < N - 1; ++i)
            {
                if (S[i] == S[i + 1])
                    ++point;
                else
                    ++revnum;
            }
            var num = Math.Min(K * 2, revnum);
            var ans = num + point;
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
template <typename T> 
using lim = numeric_limits<T>;
template <typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

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

const int N = 1e5+1;
vector<int> graph[N];
int h[N];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
    int n, m; cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> h[i];

    for (int i = 0; i < m; i++){
        int a, b; cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    int ans = 0;
    for (int u = 1; u <= n; u++){
        bool good = true;
        for (int v : graph[u]){
            good &= (h[u] > h[v]);
        }
        ans += good;
    }

    cout << ans << "\n";

}

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

const long long mod = pow(10, 9) + 7;

int main() {
	int n; cin >> n;
	long long power = 1;
	for (int i = 1; i <= n; i++) {
		power *= i;
		power %= mod;
	}
	cout << power << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[10001],b[10001];
int main()
{
	int n,ans=0;
	cin>>n;
	for(int q=1;q<=n;q++)
	{
		cin>>a[q]>>b[q];
	}
	for(int q=1;q<=n;q++)
	{
	ans+=b[q]-a[q]+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int n,m;
string u[300],t[300];
string s;

int main() {
	cout << fixed << setprecision(18);
	bool open=false;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>u[i];
	}
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>t[i];
		for(int j=0;j<n;j++){
			if(t[i]==u[j]&&!open){
				cout<<"Opened by "<<t[i]<<endl;
				open=true;
				break;
			}else if(t[i]==u[j]){
				cout<<"Closed by "<<t[i]<<endl;
				open=false;
				break;
			}
			if(j==n-1){
				cout<<"Unknown "<<t[i]<<endl;
			}
		}
	}
} 


Measured memory_bytes: 3240
// to format a document: ctrl + K -> ctrl + D

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (i % 2 == 0) continue;
        int cnt = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) cnt++;
        }
        if (cnt == 8) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [N] = input[0].map(Number);
  const students = input.slice(1, N + 1).map((line) => line.map(Number));
  const checkpoints = input.slice(N + 1, -1).map((line) => line.map(Number));

  const answer: number[] = [];

  students.forEach(([a, b]) => {
    let minDistance = Number.MAX_SAFE_INTEGER;
    let checkpoint = 0;

    checkpoints.forEach(([c, d], index) => {
      const currentDistance = Math.abs(c - a) + Math.abs(d - b);

      if (currentDistance < minDistance) {
        minDistance = currentDistance;
        checkpoint = index + 1;
      }
    });

    answer.push(checkpoint);
  });

  return answer.join("\n");
};

console.log(main(read()));


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int mod = 2019;

    int L,R;

    Scd2(L,R);

    int ans = INF;
    int l = L%mod;
    int r = R%mod;

    if( L+2019 <= R ) ans = 0;
    if( l >= r ) ans = 0;
    else {
        Repe(i,r+1,l) Repe(j,r+1,i+1) ans = min( ans, i*j%mod );
    }

    printf ("%d\n", ans );

    return 0;
}



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

ll g1 (ll n, int p) {
  if(n == 0) return 0;
  return n / p + g1(n / p, p);
}

ll g2(ll n, int p) {
  ll res = g1(n / 2, p);
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  if(n % 2 == 0) {
    ans = g2(n, 5);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N=int(input())
A = input()
B = input()
C = input()

#moji_dic={}
chage_num=0
for i in range(N):
    moji_dic={}
    moji_dic[A[i]] = moji_dic.get(A[i], 0) +1
    moji_dic[B[i]] = moji_dic.get(B[i], 0) +1
    moji_dic[C[i]] = moji_dic.get(C[i], 0) +1
    #print(moji_dic)
    if (moji_dic.keys())==[0]*N:
        no_change_num=0
    else:
        no_change_num=max(moji_dic.values())
    chage_num+=3-no_change_num
print(chage_num)

Measured memory_bytes: 3064