akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
from heapq import heappop, heappush

N, K = map(int, input().split())
TD = []

for _ in range(N):
  TD.append(tuple(map(int, input().split())))

TD.sort(key = lambda x:x[1], reverse=True)
TD += [(TD[-1][0], 0)]

D = defaultdict(list)
T = [0]*N
H = []
ans = 0

for i in range(K):
  t, d = TD[i]
  T[t-1] += 1
  D[t].append(d)
  ans += d

cnt = sum(1 for c in T if c >= 1)
ans += cnt**2

for t in range(1, N+1):
  if T[t-1] >= 2:
    heappush(H, (D[t].pop(), t))
    T[t-1] -= 1

#print(ans, H, T, cnt)
for i in range(K, N):
  if H:
    t1, d1 = TD[i]
    d2, t2 = heappop(H)
    #print(t1, d1, t2, d2)
    if T[t1-1] == 0 and d1 - d2 + 2*cnt + 1 >= 0:
      ans += d1 - d2 + 2*cnt + 1
      cnt += 1
      T[t1-1] += 1
      if T[t2-1] >= 2:
        T[t2-1] -= 1
      if T[t2-1] >= 2:
        heappush(H, (D[t2].pop(), t2))
    else:
      heappush(H, (d2, t2))
    #print(ans, H, T, cnt)

#元のやつとの組み合わせ...？
ans2 = 0
T2 = [0]*N
D2 = []
cnt2 = 0
 
for t, d in TD:
  if cnt2 < K:
    if T2[t-1]:
      D2.append(d)
    else:
      T2[t-1] = 1
      ans2 += d
      cnt2 += 1

ans2 += sum(D2[:K-cnt2]) + sum(T2)**2

print(max(ans, ans2))

Measured memory_bytes: 35696
N = int(input())

ab_list = []
for _ in range(N):
    ab_list.append(input())
    

ab_cnt = 0
a_cnt = 0
b_cnt = 0
in_cnt = 0

for tmp_list in ab_list:
    # Count 'AB'
    in_cnt += tmp_list.count('AB')
    
    # Conut start'B' and end 'A'
    if tmp_list.startswith('B') and tmp_list.endswith('A'):
        ab_cnt += 1
        
    # Count end'A'
    elif tmp_list.endswith('A'):
        a_cnt += 1
    
    # Count start'B'
    elif tmp_list.startswith('B'):
        b_cnt += 1
        
# compute count of 'AB'
if ab_cnt == 0:
    ans = min(a_cnt, b_cnt) + in_cnt
elif a_cnt + b_cnt > 0:
    ans = ab_cnt + min(a_cnt, b_cnt) + in_cnt
elif a_cnt + b_cnt == 0:
    ans = (ab_cnt -1) + in_cnt

# output
print(ans)

Measured memory_bytes: 3700
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	string s;
	cin>>n;
	cin>>s;
	int len=s.size();
	for(int i=0;i<len;i++)
	{
		cout<<char((s[i]-'A'+n)%26+'A');
	}
	cout<<endl;
	return 0;
}

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

using namespace std;

#define lli long long int
#define MOD 1000000007
#define DEBUG 0
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,n) for(lli i=1;i<=n;i++)

map<lli,map<string,lli>> m;
lli n;

bool ok(string last4){
	if(DEBUG)cout<<endl<<"last4="<<last4<<endl;
	for(lli i=0;i<4;i++){
		string t = last4;
		if(i!=0)swap(t[i],t[i-1]);
		if(t.find("AGC") != -1){
			if(DEBUG)cout<<"NG"<<t<<endl;
			return false;
		}
	}
	return true;
}

lli dfs(lli depth,string last3){
	if(DEBUG)cout<<"depth =" <<depth <<" last3="<<last3<<endl;
	if(m[depth][last3] != 0)return m[depth][last3];
	if(depth == n)return 1;
	lli ret = 0;
	string c[4] = {"A","G","C","T"};
	if(DEBUG)cout<<"unko"<<endl;
	REP(i,4){
		if(ok(last3+c[i])){
			string next = last3.substr(1,2)+c[i];
			ret = ret + dfs(depth+1,next)%MOD;
		}
	}
	m[depth][last3] = ret;
	return ret;
}

int main(){

	cin>>n;
	dfs(0,"TTT");
	cout<<m[0]["TTT"]%MOD<<endl;

	return 0;
}



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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

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

	int x = abs(a - b);
	int y = abs(a - c);

	if (x > y)cout << 'B' << endl;
	else cout << 'A' << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int main(){
    ll n,m; cin>>n>>m;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll tmp=a[0]/2;
    rep(i,n-1){
        tmp=(tmp*a[i+1]/2)/gcd(tmp, a[i+1]/2);
    }
    ll res=0;
    bool ifhalf=true;
    rep(i,n){
        if(tmp%a[i]==0) ifhalf=false;
    }
    if(!ifhalf){
        res=0;
    }else{
        res=((m/tmp)+1)/2;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  int a,b;
  int now=0;
  int cnt=0;
  cin >> a >> b;
  if(b==1){
    cout << 0;
    return 0;
  }
  for(int i=1;i<=200;i++){
      if((a*i-(i-1))>=b){
        cout << i;
        return 0;
      }
  }
}


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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n, o = 1;
    vector<int> v;
    cin >> n;
	int h;
    cin >> h;
    v.push_back(h);
    n--;
    while(n--){
    	int hi;
    	cin >> hi;
    	if(hi >= *max_element(v.begin(), v.end())) o++;
    	v.push_back(hi);
    }
    cout << o << endl;
}

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

int main(){
    string s, t;
    cin >> s >> t;
    bool judge = false;
    for(int i = 0;i < s.size();i++){
        if(s == t)judge = true;
        string memo = s;
        s = memo.at(memo.size() - 1);
        memo.pop_back();
        s += memo;
    }
    if(judge)cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

#define ll long long
#define ar array


int n;


void solve(){
    
    cin >> n;

    cout << n + n*n + n*n*n << endl;

}





int main(){

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

    solve();

}

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

# define MAXN 100005
# define INF 1000000000
# define MOD 1000000007

# define vii vector<int>
# define vll vector<long long int>
# define sii set<int>
# define sll set<long long int>
# define scc set<char>
# define usii unordered_set<int>
# define usll unordered_set<long long int>
# define uscc unordered_set<char>
# define mii map<int,int>
# define mll map<long long int,long long int>
# define mci map<char,int>
# define umii unordered_map<int,int>
# define umll unorderd_map<long long int,long long int>
# define umci unordered_map<char,int>
# define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

# define fori(i,range) for(int i=0;i<range;i++)
# define forl(i,range) for(long long int i=0;i<range;i++)
# define w(t) int t;cin>>t;while(t--)

# define F first
# define S second

# define printa(a,n) for(int idnphq=0;idnphq<n;idnphq++) cout << a[idnphq] << " ";cout << "\n";  // only for debugging (of arrays and vectors) thus int
# define prints(s) for(auto idnphq=s.begin();idnphq!=s.end();idnphq++) cout<< *idnphq << ' ';cout << "\n"; // only for debugging (of sets)
# define printm(m) for(auto idnphq=m.begin();idnphq!=m.end();idnphq++) cout<< idnphq->first << ':' << idnphq->second << ' ';cout << "\n"; //ofd

typedef long long ll;
typedef pair<int, int> P;
//--------------------------------------------------------------------------------------------
int ans[MAXN];
int main()
{
    fastio;
    int n;
    cin>>n;
    int a[n][2];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<2;j++)
        {
            cin>>a[i][j];
        }
    }

    for(int i=0;i<n;i++)
    {
       if(a[i][0]==a[i][1])
       {
           ans[i]=1;
       }else{ans[i]=0;}        
    }
    bool bhul=false;
    for(int i=0;i<n;i++)
    {
        if(ans[i]==1)
        {
            if(ans[i+1]==1&&ans[i+2]==1)
            {
                bhul=true;break;
            }else
            {
                continue;
            }
            
        }else{continue;}
    }
    if(bhul==true){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}

    return 0;
}


Measured memory_bytes: 3652
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int data[] = new int[n];
		int min = 1000000;
		int max = 0;

		for (int i = 0;i<n ;i++ ) {
			data[i] = sc.nextInt();
			max = Math.max(max,data[i]);
		}

		for (int i = 1;i<max*2 ;i++ ) {
			int sum = 0;
			for (int j = 0;j<n ;j++ ) {
				sum = sum + (data[j]-i)*(data[j]-i);
			}
			min = Math.min(min,sum);
		}

		System.out.println(min);



	}
}


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void pout(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void pout(const T &value, const Args&... args){std::cout << value << " ";pout(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int N;
  while(cin >> N){
    vector<int> A(N-1); cin >> A;

    vector<int> ans(N);

    REP(i,N-1){
      ans[A[i]-1] += 1;
    }
    
    join(cout, ALL(ans), "\n");
  }


  return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)turn idx;
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  rep(X, 1, 50001) {
    if ((X * 108) / 100 == N) {
      ans = X;
      break;
    }
  }

  if (ans == 0) {
    cout << ":(" << endl;
  } else {
    cout << ans << endl;
  }
};


Measured memory_bytes: 256
n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]

from itertools import combinations_with_replacement

ans=0
for a in combinations_with_replacement(range(1, m+1,), n):
    d=0
    for i in range(q):
        if a[abcd[i][1]-1]-a[abcd[i][0]-1]==abcd[i][2]:
            d+=abcd[i][3]
    ans=max(ans,d)
print(ans)


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

template <int mod = 1000000007>
struct Combination {
  std::vector<long long> fac, finv, inv;
  Combination(const long long n)
      : fac(n + 1, 0), finv(n + 1, 0), inv(n + 1, 0) {
    for (long long i = 0; i < n + 1; ++i) {
      bool one_or_zero = i == 0 || i == 1;
      fac[i] = one_or_zero ? 1 : fac[i - 1] * i % mod;
      inv[i] = one_or_zero ? 1 : mod - inv[mod % i] * (mod / i) % mod;
      finv[i] = one_or_zero ? 1 : finv[i - 1] * inv[i] % mod;
    }
    inv[0] = 0;
  }
  long long operator()(const long long n, const long long r) {
    if (n < r || n < 0 || r < 0)
      return 0;
    else if (n == r || r == 0)
      return 1;
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
  }
  long long perm(const long long n, const long long r) {
    if (n < r || n < 0 || r < 0)
      return 0;
    else if (r == 0)
      return 1;
    return fac[n] * finv[n - r] % mod;
  }
};


signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll x, y;
  cin >> x >> y;
  if((2 * x - y) % 3 == 0 && (- x + 2 * y) % 3 == 0) {
    ll n, m;
    n = (2 * x - y) / 3;
    m =(- x + 2 * y) / 3;
    Combination<MOD> comb(n + m + 1);
    out(comb(n + m, n));
  }
  else out(0);


  return 0;
}


Measured memory_bytes: 18784
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

struct Node {
	int v;
	Node *p, *l, *r;
};

Node *root;

void insert(int v) {
	Node *p = root;
	Node *u;
	u = (Node *)malloc(sizeof(Node));
	u->v = v;
	u->l = u->r = nullptr;
	while (p != nullptr) {
		u->p = p;
		if (u->v < p->v)
			p = p->l;
		else
			p = p->r;
	}
	if (p == root)
		root = u;
	else {
		if (u->v < u->p->v)
			u->p->l = u;
		else
			u->p->r = u;
	}
}

void inorder(Node *u) {
	if (u == nullptr)return;
	inorder(u->l);
	cout << ' ' << u->v;
	inorder(u->r);
}

void preorder(Node *u) {
	if (u == nullptr)return;
	cout << ' ' << u->v;
	preorder(u->l);
	preorder(u->r);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	rep(i, 0, n) {
		string com;
		cin >> com;
		if (com[0] == 'i') {
			int key; cin >> key;
			insert(key);
		}
		else {
			inorder(root); cout << endl;
			preorder(root); cout << endl;
		}
	}
	return 0;
}

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

typedef long long s64;

int main()
{
//	freopen("1.in","r",stdin);
	s64 n,s;
	cin>>n>>s;
	if(n==s)
	{
		cout<<n+1;
		exit(0);
	}
	s64 b=2;
	for(;b*b<=n;++b)
	{
		s64 now=0;
		s64 x=n;
		while(x)
		{
			now+=x%b;x/=b;
		}
		if(now==s)
		{
			cout<<b;
			exit(0);
		}
	}
	s=n-s;
	while(b<=n)
	{
		s64 _b=n/(n/b); 
		if(s%(n/b)==0)
		{
			s64 i=s/(n/b)+1;
			if(i>=b&&i<=_b)
			{
				cout<<i;
				exit(0);
			}
		}
		b=_b+1;
	}
	puts("-1"); 
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
 int a,b,c,n;
 scanf("%d%d%d",&a,&b,&c);
 if(a<1 || b<1 || c<1 || a>100 || b>100 || c>100)
   printf("正しい値を入力してください。\n");
 n=b/a;
 if(n>=c){
   printf("%d\n",c);
 }
 else if(n<c){
   printf("%d\n",n);
 }
 return 0;
}


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

int xx=753;

int main(){
  long long s,ma=1000;
  cin >> s;
  
  while(s>100){
    ma=min(ma,abs(s%1000-xx));
    s/=10;
  }
  cout << ma;
}

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

Measured memory_bytes: 256
N,K=map(int,input().split())
t=list(map(int,input().split()))
g=[1]
for i in range(N-1):
  g.append(t[g[i]-1])
if K>len(g):
  a=g.index(g[-1])
  b=len(g)-a-1
  K=(K-a)%b+a
print(g[K])

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N, M;
	cin >> N >> M;
	cout << min(M/2,N)+max(0ll,(M-N*2)/4) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>

using namespace std;
int a[4];
int b[4];

int degree[5];	//度
//两个度为1，两个度为2 

int main()
{
	for (int i = 0 ; i < 3 ; i++)
	{
		scanf("%d%d", &(a[i]), &(b[i]));
		degree[a[i]]++;
		degree[b[i]]++;
	}
	
	int oneCount = 0;
	int twoCount = 0;
	for (int i = 1 ; i <= 4 ; i++)
	{
		if (degree[i] == 1)
			oneCount++;
		else
			twoCount++;
	}
	
	if (oneCount == 2 && twoCount == 2)
		printf("YES\n");
	else
		printf("NO\n");


	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
using vi = vector<int>;
using vll = vector<ll>;
ll fast_exp(ll base,ll e){
    ll r=1;
    while(e>0){
        if(e%2)r=(r*base);
        base=base*base;
        e/=2;
    }
    return r;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    int n,k;cin>>n>>k;
    vector<int> v(n);for(int i=0;i<n;i++)cin>>v[i];
    vector<char> dp(k+1,'L');
    // dp[0]='L';
    int i=0;
    int x=0;
    while(i<=k){
        for(int j=0;j<n;j++){
            if(i+v[j]>k||dp[i]=='W')break;
            dp[i+v[j]]='W';
        }
        i++;
    }
    if(dp[k]=='W')cout<<"First";
    else cout<<"Second";
    
}

Measured memory_bytes: 384
n, m = map(int, input().split())
ss = input().split()
ts = input().split()
d = [[1] * (m+1) for _ in range(n+1)]
for i in range(n):
    for j in range(m):
        d[i+1][j+1] = (d[i][j+1] + d[i+1][j] - (ss[i] != ts[j])*d[i][j]) % (10**9+7)
print(d[n][m])


Measured memory_bytes: 72412
from decimal import *
N, K = map(int, input().split())

ans = Decimal(0)
if K <= N:
    ans += Decimal(max(N-K+1, 0))/Decimal(N)
thres = N+1
if K <= N:
    thres = K

for i in range(1, thres):
    p = Decimal(1/N)
    score = Decimal(i)
    while score < K:
        score = score * Decimal(2)
        p = p / Decimal(2)
    ans = ans + p

print(ans)


Measured memory_bytes: 110676
package main

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

func main() {
	N, K := ReadInt(), ReadInt()
	S := Read()

	ans := 0
	prev := byte(' ')
	for i := 0; i < len(S); i++ {
		if S[i] == prev {
			ans++
		}
		prev = S[i]
	}
	fmt.Println(Min(ans+2*K, N-1))
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var sc = bufio.NewScanner(os.Stdin)

func init()        { sc.Buffer(make([]byte, 256), 1e9); sc.Split(bufio.ScanWords) }
func Read() string { sc.Scan(); return sc.Text() }

func ReadInt() int {
	v, e := strconv.Atoi(Read())
	if e != nil {
		panic(e.Error())
	}
	return v
}


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

ll dp[100005];

int main(){
    ll n,w;
    scanf(" %lld %lld",&n,&w);
    for(int i = 0; i < 100005;++i) dp[i] = 1000000000000ll;
    dp[0] = 0;
    while(n--){
        ll we; int va;
        scanf(" %lld %d",&we,&va);
        for(int i = 100004; i > -1;--i)
            if(i-va > -1) dp[i] = min(dp[i],dp[i-va]+we);
    }
    int ans = 0;
    for(int i = 100004; i > -1 && !ans;--i){
        if(dp[i] <= w) ans = i;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>
#include <cassert>
#ifdef DEBUG
#include "./Lib/debug.hpp"
#else
#define dump(...)
template<class T>inline auto d_val(T a, T b) { return a; }
#endif

/* (=＾o＾=) */
#define int ll

/* macro */
#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define REPI2(it,b,e) for(auto it = (b); it != (e); ++it)
#define REPI(it,c) REPI2(it, (c).begin(), (c).end())
#define RREPI(it,c) REPI2(it, (c).rbegin(), (c).rend())
#define REPI_ERACE2(it, b, e) for(auto it = (b); it != (e);)
#define REPI_ERACE(it, c) REPI_ERACE2(it, (c).begin(), (c).end())
#define ALL(x) (x).begin(),(x).end()
#define cauto const auto&
/* macro func */
#define SORT(x) do{sort(ALL(x));}while(false)
#define RSORT(x) do{sort((x).rbegin(),(x).rend());}while(false)
#define UNIQUE(v) do{v.erase( unique(v.begin(), v.end()), v.end() );}while(false)
#define MAX(x,y) do{x = std::max(x,y);}while(false)
#define MIN(x,y) do{x = std::min(x,y);}while(false)
#define BR do{cout<<"\n";}while(false)

/* type define */
using ll = long long;
using PAIR = std::pair<ll, ll>;
using VS = std::vector<std::string>;
using VL = std::vector<long long>;
using VVL = std::vector<VL>;
using VVVL = std::vector<VVL>;
using VD = std::vector<double>;
template<class T>
using V = std::vector<T>;

/* using std */
using std::cout;
constexpr char endl = '\n';
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::unordered_multiset;
using std::multiset;
using std::bitset;
using std::priority_queue;

/* constant value */
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;

/* Initial processing  */
struct Preprocessing { Preprocessing() { std::cin.tie(0); std::ios::sync_with_stdio(0); }; }_Preprocessing;

/* Remove the source of the bug */
signed pow(signed, signed) { assert(false); return -1; }

/* define hash */
namespace std { template <>	class hash<std::pair<ll, ll>> { public:	size_t operator()(const std::pair<ll, ll>& x) const { return hash<ll>()(1000000000 * x.first + x.second); } }; }

/* input */
template<class T> std::istream& operator >> (std::istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }

//=============================================================================================

signed main() {
	string str;
	cin >> str;
	if (str[0] == 'S') {
		cout << "Cloudy" << endl;
	} else if (str[0] == 'R') {
		cout << "Sunny" << endl;
	} else {
		cout << "Rainy" << endl;
	}
}

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

int main()
{
	int n, k;
	int a[200000];
	cin >> n >> k;
	rep(i, n){
		scanf("%d", &a[i]);
	}
	sort(a, a+n);

	priority_queue<int> pq;
	int cnt=1;
	int tmp=a[0];
	for(int i=1; i<n; i++){
		if(tmp != a[i]){
			pq.push(cnt);
			tmp = a[i];
			cnt=1;
		}else{
			cnt++;
		}
	}
	pq.push(cnt);




	rep(i, k){
		pq.pop();
	}


	int size = pq.size();
	// cout << "size" << size << endl;
	int num =0;
	rep(i, size){
		num += pq.top();
		pq.pop();
	}

	cout << num << endl;


}



Measured memory_bytes: 2168
#include<iostream>
#include<sstream>
#include<iomanip>
#include<bitset>
#include<cmath>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<limits.h>
using namespace std;

typedef long long LL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN=1e5+10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    double a,b;
    cin>>a>>b;
    if(b>=a)
        cout<<1<<endl;
    else
        cout<<ceil(a/b)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
#include <stdio.h>
using namespace std;

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int64 a, b, g;
    cin >> a >> b;
    int64 t = a * b;
    while (a != 0 && b != 0){
        if (a > b) a %= b; else b %= a;
    }
    cout << t / (a + b);
    return 0;
}


Measured memory_bytes: 256
// AOJ 3130 Calculation Training
// 2020.1.14 bal4u

#include <stdio.h>

typedef long long ll;

int main()
{
	ll N; int i, A, B;
	
	scanf("%lld%d%d", &N, &A, &B);
	N %= 12;
	i = 0; while (i < N) {
		A = A-B, ++i;
		if (i == N) break;
		B = A+B, ++i;
	}
	printf("%d %d\n", A, B);
	return 0;
}



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

using namespace std;

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

const double ESP=1e-10;

double x[4],y[4];

int main(){
	int n;
	scanf("%d",&n);
	REP(i,n){
		REP(j,4){
			scanf("%lf %lf",&x[j],&y[j]);
		}
		if (fabs(x[0]-x[1])<=ESP || fabs(x[2]-x[3])<=ESP){
			if (fabs(x[0]-x[1])<=ESP && fabs(x[2]-x[3])<=ESP){
				printf("YES\n");
			}
			else{
				printf("NO\n");
			}
		}
		else{
			if (fabs((y[0]-y[1])/(x[0]-x[1])-(y[2]-y[3])/(x[2]-x[3]))<=ESP){
				printf("YES\n");
			}
			else{
				printf("NO\n");
			}
		}
	}
	return 0;
}

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

const int MAX_LEN = 300005;

typedef long long llong;

using namespace std;

int arr [MAX_LEN];

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

  for (int i = 0; i < 3 * length; i++) {
    cin >> arr[i];
  }

  sort(arr, arr + 3 * length, greater<int>());

  llong ans = 0;
  for (int i = 0; i < length; i++) {
    ans += arr[2 * i + 1];
  }

  cout << ans << endl;
}


Measured memory_bytes: 1408
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  cin >> N;

  long keta = 0;
  long nines = 0;
  long first;

  while (N) {
    keta ++;
    if (N % 10 == 9) nines++;
    first = N % 10;
    N /= 10;
  }

  if (nines == keta) cout << 9 * keta << endl;
  else if (nines == keta - 1 and first != 9) cout << first + nines * 9 << endl;
  else cout << (first - 1) + (keta - 1) * 9 << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

// ans * 8/100 = A
// A*100 <= ans*8 < A*100 + 100
// ans * 10/100 = B
// B*10 <= ans < B*10 + 10

int main()
{
    int A, B;
    cin >> A >> B;
    for(int ans = 1; ans <= 2000; ++ans) {
        if(A*100 <= ans*8 && ans*8 < A*100 + 100 && B*10 <= ans && ans < B*10 + 10) {
                cout << ans << endl;
                return 0;
            }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

typedef long long ll;
#define pb push_back
#define mp make_pair



void solve()
{
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    cout << n * m - m * a - n * b + a * b;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.in", "r", stdin);freopen("/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.out", "w", stdout);
    
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

class UF
{
private:
	vector<int> root;
	vector<long long int> black;
	vector<long long int> white;

public:
	UF(int n)
	{
		root = vector<int>(n, -1);
		black = vector<long long int>(n, 0);
		white = vector<long long int>(n, 0);
	}

	int getRoot(int x)
	{
		if(root[x] == -1) return x;
		else return root[x] = getRoot(root[x]);
	}

	long long int getBlack(int x)
	{
		return black[getRoot(x)];
	}

	long long int getWhite(int x)
	{
		return white[getRoot(x)];
	}

	void update(int x, int y)
	{
		x = getRoot(x);
		y = getRoot(y);
		if(x == y) return;
		if(x > y) swap(x, y);
		root[y] = x;
		black[x] += black[y];
		white[x] += white[y];
	}

	void addBlack(int x)
	{
		black[getRoot(x)]++;
	}

	void addWhite(int x)
	{
		white[getRoot(x)]++;
	}

};

int main()
{
	int h, w;
	cin >> h >> w;
	UF uf(h * w);
	char s[500][500];
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >> s[i][j];
		}
	}

	int di[2] = {1, 0};
	int dj[2] = {0, 1};
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			for(int k = 0; k < 2; k++){
				int ni = i + di[k];
				int nj = j + dj[k];
				if(ni >= h || nj >= w) continue;
				if(s[i][j] != s[ni][nj]){
					uf.update(i * w + j, ni * w + nj);
				}
			}
		}
	}

	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '.') uf.addBlack(i * w + j);
			else uf.addWhite(i * w + j);
		}
	}

	long long int ans = 0;
	for(int i = 0; i < h * w; i++){
		// cout << uf.getRoot(i) << " " << uf.getBlack(i) << " " << uf.getWhite(i) << endl;
		if(uf.getRoot(i) == i) ans += uf.getBlack(i) * uf.getWhite(i);
	}
	cout << ans << endl;
}

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main(){
  FAST();

  string str;
  cin >> str;
  int ans = 0;

  REP(i, 0, str.length()/2){
      if(str[i] != str[str.length() - 1 - i])
        ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n ; i++){
        cin>>a[i];
    }
    int count=0;
    for(int i=0; i<n; i++){
        if(a[i]%2==0){
            count++;
        }
    }
    int res=0;
    for(int i=0; i<n; i++){
        if(a[i]%2==0 &&(a[i]%3==0 || a[i]%5==0)){
            res++;
        }
    }
    if(count==res){
        puts("APPROVED");
        
    }
    else{
        puts("DENIED");

    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;

  int s;
  s = a * b;

  if (s == 6) {
    cout << 1 << endl;
  } else if (s == 3) {
    cout << 2 << endl;
  } else {
    cout << 3 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sc(x) scanf("%d", &x)
#define pr(x) printf("%d\n", x)
#define lowbit(x) (x & -x)
#define ll long long
#define memset(x) memset(x, 0, sizeof(x))
#define fre freopen(FILE".in", "r", stdin); freopen(FILE".out", "w", stdout);
#define FILE ""
using namespace std;
const int N = 100010;
int tot = 0, head[N], sum, n, k, ans = 9999999;
struct txljjkyzy
{
	int next, to;
}e[N * 2];
void add(int x, int y)
{
	e[++tot].to = y;
	e[tot].next = head[x];
	head[x] = tot;
}
void dfs(int x, int fa, int d)
{
	if (d > k / 2) return;
	sum++;
	for (int i = head[x]; i; i = e[i].next)
	{
		int y = e[i].to;
		if (y == fa) continue;
		dfs(y, x, d + 1);
	}
}
int main()
{
//	fre;
	sc(n);
	sc(k);
	for (int i = 1; i < n; i++)
	{
		int x, y;
		sc(x);
		sc(y);
		add(x, y);
		add(y, x);
	}
	if (k % 2 == 0)
	{
		for (int i = 1; i <= n; i++)
		{
			sum = 0;
			dfs(i, 0, 0);
			ans = min(ans, n - sum);
		}
	}
	else
	{
		for (int i = 1; i <= n; i++)
		for (int j = head[i]; j; j = e[j].next)
		{
			int y = e[j].to;
			sum = 0;
			dfs(i, y, 0);
			dfs(y, i, 0);
			ans = min(ans, n - sum);
		}
	}
	cout << ans << endl;
	return 0;
}


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

public class Main {

	private static class Dice {
		private String top;
		private String bottom;
		private String front;
		private String back;
		private String left;
		private String right;

		public Dice(
				String top,
				String front,
				String right,
				String left,
				String back,
				String bottom)
		{
			this.top = top;
			this.front = front;
			this.right = right;
			this.left = left;
			this.back = back;
			this.bottom = bottom;
		}

		public String operationE() {
			String tmp = this.top;
			this.top = this.left;
			this.left = this.bottom;
			this.bottom = this.right;
			this.right = tmp;

			return this.top;
		}

		public String operationN() {
			String tmp = this.top;
			this.top = this.front;
			this.front = this.bottom;
			this.bottom = this.back;
			this.back = tmp;

			return this.top;
		}

		public String operationS() {
			String tmp = this.top;
			this.top = this.back;
			this.back = this.bottom;
			this.bottom = this.front;
			this.front = tmp;

			return this.top;
		}

		public String operationW() {
			String tmp = this.top;
			this.top = this.right;
			this.right = this.bottom;
			this.bottom = this.left;
			this.left = tmp;

			return this.top;
		}

		private boolean frontFind(String frontNum) {
			for(int i = 0; i < 4; i++){
				this.operationS();
				if (this.front.equals(frontNum)){
					return true;
				}
			}
			return false;
		}

		private void topFind(String topNum) {
			for(int i = 0; i < 4; i++) {
				this.operationW();
				if(this.top.equals(topNum)) {
					return;
				}
			}
		}

		public String answerNum(String topNum, String frontNum){
			boolean frontFound = frontFind(frontNum);

			if(!frontFound) {
				this.operationE();
				frontFind(frontNum);
			}

			topFind(topNum);

			return this.right;
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] label = br.readLine().split(" ");
		Dice dice = new Dice(label[0], label[1], label[2], label[3], label[4], label[5]);

		int orderNum = Integer.parseInt(br.readLine());

		for (int i = 0; i < orderNum; i++){
			String[] order = br.readLine().split(" ");
			String result = dice.answerNum(order[0], order[1]);

			System.out.println(result);
		}
	}
}

Measured memory_bytes: 24172
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;
int main(){
    ll n;
    cin>>n;
    ll max=0;
    for(ll i=1;i*i<=n;i++){
        if(0==n%i){
            max=i;
        }
    }
    cout<<max+n/max-2;
    return 0;
}

Measured memory_bytes: 256
#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() {
	ll  a, b,c;
	cin >> a>>b>>c;
	if (c - a - b > 0) {
		if (4 * a * b < (c - a - b) * (c - a - b))cout << "Yes";
		else cout << "No";
	}
	else {
		cout << "No";
			}

	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define p_b push_back
#define e_b emplace_back
#define m_p make_pair
#define m_t make_tuple

using namespace std;

int main() {
	ld d, t, s;
	cin >> d >> t >> s;

	if (d / s <= t) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}

	return 0;
}

Measured memory_bytes: 3700
n, q = map(int, input().split())
P = []
T = []
for i in range(n):
    p, t = map(str, input().split())
    P.append(p)
    T.append(int(t))

EndP = []
EndT = []
time = 0
while True:
    if T==[]:
        break
    
    if T[0]>q:
        T.append(T[0]-q)
        T.pop(0)
        P.append(P[0])
        P.pop(0)
        time += q
    
    if T[0]<=q:
        EndP.append(P[0])
        P.pop(0)
        time += T[0]
        EndT.append(time)
        T.pop(0)

for i in range(n):
    print(EndP[i],EndT[i])


Measured memory_bytes: 11104
import sys
from itertools import product

input = sys.stdin.readline


def main():
    N = int(input())

    ans = []
    if N % 2 == 0:
        groups = [(1 + i, N - i) for i in range(N // 2)]
    else:
        groups = [(1 + i, N - 1 - i) for i in range((N - 1) // 2)] + [(N,)]

    for i in range(len(groups) - 1):
        group_a = groups[i]
        group_b = groups[i + 1]
        for a, b in product(group_a, group_b):
            ans.append(f"{a} {b}")

    if len(groups) >= 3:
        group_a = groups[0]
        group_b = groups[-1]
        for a, b in product(group_a, group_b):
            ans.append(f"{a} {b}")

    print(len(ans))
    print("\n".join(ans))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9228
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
int r, d;
long long x;
void solve() {
    //x = x(2000)
    cin >> r >> d >> x;
    for (int i = 0; i < 10; ++i) {
        x = r * x - d;
        cout << x << endl;
    }
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
}

Measured memory_bytes: 256
def findSumDigits(n):
  sum = 0 
  while (n > 0):
    sum += n % 10
    n = n//10
  return sum
    
def main():
  N, A, B = map(int, input().split())
  allsum = 0
  for n in range(1, N+1):
    sum = findSumDigits(n)
    if (A <= sum <= B):
      allsum += n
      
  print(allsum)
  
main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
// ifstream fin("filename.in");
// ofstream fout("filename.out");

int main(){
	int x;
	cin>>x;
	if(x<=599)
		cout<<8;
	else if(x>599 && x<=799)
		cout<<7;
	else if(x>799 && x<=999)
		cout<<6;
	else if(x>999 && x<=1199)
		cout<<5;
	else if(x>1199 && x<=1399)
		cout<<4;
	else if(x>1399 && x<=1599)
		cout<<3;
	else if(x>1599 && x<=1799)
		cout<<2;
	else if(x>1799 && x<=1999)
		cout<<1;
}


Measured memory_bytes: 3636
N, M = map(int,input().split())
KA = [list(map(int,input().split())) for i in range(N)]

l = []
for i in KA:
    l.append(i[1:])
    
ans = set(l[0])

for i in range(N):
    ans = ans & set(l[i])

print(len(ans))

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <atcoder/all>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;
using namespace atcoder;

//const ll mod=998244353;

using mint=modint998244353;

mint nine=9,ten=10;

mint ID=0;

struct S{
    mint val,w;
};

S op(S a,S b){
    return {a.val*b.w+b.val,a.w*b.w};
}

S e(){
    return {0,10};
}

using F=mint;

S mapping(F f,S x){
    if(f==ID) return x;
    return {f*(x.w-1)/nine,x.w};
}

F composition(F f,F g){
    if(f==ID) return g;
    return f;
}

F id(){
    return ID;
}

int main(){
  
    ios;
    ll n,q;
    cin >> n >> q;
    lazy_segtree<S,op,e,F,mapping,composition,id> t(n);
  t.apply(0,n,1);
    rep(i,q){
        ll l,r,d;
        cin >> l >> r >> d;
        l--;
        t.apply(l,r,d);
        mint ans=t.prod(0,n).val;
        ans/=ten;
        cout << ans.val() << endl;
    }
    return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

ll N;
ll A, B, C;
vector<int> l;

int dfs(ll i, ll a, ll b, ll c){
    if(i == N){
        if(min(min(a,b),c) == 0){
            return INF;
        }
        else{
            return abs(a-A) + abs(b-B) + abs(c-C) - 30;
        }
    }
    vector<ll> ans(4);

    ans[0] = dfs(i+1, a, b, c);
    ans[1] = dfs(i+1, a+l[i], b, c)+10;
    ans[2] = dfs(i+1, a, b+l[i], c)+10;
    ans[3] = dfs(i+1, a, b, c+l[i])+10;

    int mx = (int)*min_element(ans.begin(), ans.end());  
    return mx;
}
int main()
{
    cout << fixed << setprecision(15);
    
    cin >> N;
    cin >> A >> B >> C;

    REP(i, N){
        ll t;
        cin >> t;
        l.push_back(t);
    }

    cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
 
def main():
    input = sys.stdin.readline
    S = str(input().strip())
 
    cnt_01 = 0
    cnt_10 = 0
    for i in range(len(S)):
        s = S[i]
 
        if i % 2 == 0:
            if s != '0':
                cnt_01 += 1
            else:
                cnt_10 += 1
        else:
            if s != '0':
                cnt_10 += 1
            else:
                cnt_01 += 1
 
    return min(cnt_01, cnt_10)
 
 
if __name__ == '__main__':
    print(main())

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

typedef long long int llint;

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

  char b = n[0];
  
  if(b < n[1] || b < n[2])
    n[0] = n[1] = n[2] = b + 1;
  else
    n[0] = n[1] = n[2] = b;
  
  cout<< n <<endl;
  
  return 0;
}


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


#define DB(x) cout << ##x << x
#define DB2(x,y) cout << #x << ' ' << x << '|' << #y << ' '<< y << '\n'


class SegmentTree
{
  public:
  SegmentTree(int n)
  {
    this->n = n;
    vec_.resize(4 * n);

  }


  long long int query(int low, int high)
  {
    return query(low, high, 1, 0, n-1);
  }

  void add(int index, long long int value)
  {
    add(index, value, 1, 0, n-1);

  }

  void debug()
  {
    debug(1, 0, n-1);
  }


  private:
  vector<long long> vec_;
  int n;
  int left(int x) { return x * 2; }
  int right(int x) { return left(x) + 1;}
  long long int query(int ql, int qu, int current, int rl, int ru)
  {
    if (qu < rl or ql > ru)
      return 0;
    if (rl >= ql and ru <= qu)
       return vec_[current];
    if (rl == ru)
      return vec_[current];
    int mid = (rl + ru)/2;
    return max(query(ql, qu, left(current), rl, mid), query(ql,qu, right(current), mid + 1, ru));
  }

  void add(int index, long long  int val, int current, int rl, int ru)
  {
    if ( index > ru or index < rl)
      return;
    if (rl == index and ru == index)
    {
      vec_[current] = val;
      return;
    }
    vec_[current] = max(vec_[current], val);
    int mid = (rl + ru)/2;
    add(index, val, left(current), rl, mid);
    add(index, val, right(current), mid + 1, ru);
  }


  void debug(int current, int rl, int ru)
  {
    cout << "Range : " << rl <<'-' << ru << ':' << vec_[current] <<'\n';
    if (rl ==  ru) {
      return;
    }
    int mid = (rl + ru)/2;
    debug(left(current), rl, mid);
    debug(right(current), mid + 1, ru);
  }


};


int main()
{
  int n;
  cin >> n;
  vector<int> a(n), h(n);
  for (int i = 0; i < n; ++i) cin >> h[i];
  for (int i = 0; i < n; ++i) cin >> a[i];
  // dp[i] : max value ending at index i
  // dp[i] = max(dp[j] , where j < i and h[j] < h[i]
  SegmentTree ds(n);
  long long int result = 0;
  ds.add(h[0], a[0]);
  result = a[0];
  for (int i = 1; i < n; ++i) {
    auto maxi = ds.query(0, h[i]);
    auto p = maxi + a[i];
    //ds.debug();
    ds.add(h[i], p);
    result = max(result, p);
  }
  cout << result << '\n';

  return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main(){
    string s;
    cin >> s;
    int n = s.size();

    ll ans = 0;
    ll tmp;
    for(int bit=0; bit<1<<n-1; bit++) {
        for(int i=0; i<n-1; i++) {
            tmp *= 10;
            tmp += s[i]-'0';
            if(bit>>i&1) {
                ans += tmp;
                tmp = 0;
            }
        }
        tmp *= 10;
        tmp += s.back()-'0';
        ans += tmp;
        tmp = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define mp std::make_pair
#define pb push_back
typedef long long ll;
int cnt[200005];
int main()
{
	// freopen("ARC102-C.in", "r", stdin);
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++)
		cnt[i % k]++;
	ll ans = 0;
	for (int i = 0; i < k; i++)
	{
		int x = (k - i) % k, y = (k - i) % k;
		if ((x + y) % k == 0)
			ans += (ll)cnt[i] * cnt[x] * cnt[y];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 640