akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, start, end) for(int i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

template<typename A, size_t N, typename T>
void array_fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int n;
    cin >> n;
    vector<ll> a(n, INFL), b(n-1);
    rep(idx, n-1) cin >> b[idx];

    ll ans;
    rep(i, n-1) {
        a[i] = min(a[i], b[i]);
        a[i+1] = min(a[i+1], b[i]);
    }

    cout << accumulate(all(a), 0) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main() {
	char s[101];
	long long k;
	scanf("%s%lld", s, &k);
	for (int i = 0; i < k; i++) {
		if (s[i] != '1') {
			printf("%c\n", s[i]);
			return 0;
		}
	}
	printf("1\n");
	return 0;
}

Measured memory_bytes: 128
n=int(input())
ls=list(map(int,input().split()))
mxmx=0
mx=0
tmp=0
previous=ls.pop(0)
for i,v in enumerate(ls):
    if v<=previous:
        mx+=1
    else:
        if mx>mxmx:
            mxmx=mx
        mx=0
    previous=v
if mx>mxmx:
    mxmx=mx
print(mxmx)

Measured memory_bytes: 63856
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

int main() {
    int n, m, k;
    cin >> n >> m >> k;

    bool ok = false;
    rep(i, n+1) rep(j, m+1) {
        int b = i * (m - j) + j * (n - i);
        if (b == k) ok = true;
    }
    cout << (ok ? "Yes" : "No") << endl;
}


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

using namespace std;

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;

  bool ok = false;
  for (int i = 1; i < b; i++) {
    if (a * i % b == c) {
      ok = true;
      break;
    }
  }

  cout << (ok ? "YES" : "NO") << endl;

  return 0;
}

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

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep1(n) rep2(i,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
int main(){
    int n;
    cin>>n;
    string a,b,c;
    cin>>a>>b>>c;
    int count=0;
    for(int i=0;i<n;i++){
        char cha=a[i],chb=b[i],chc=c[i];
        int memo=0;
        if(cha==chb)memo++;
        if(chc==chb)memo++;
        if(cha==chc)memo++;
        if(memo==0)count=count+2;
        else if(memo==1)count=count+1;
    }
    cout<<count<<endl;
}

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

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; }
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
using Graph = vector<vector<int>>;
queue<int> quex,quey;

int main(){
   int n,k,cnt=0; cin >> n >> k;
   for(int i=0;1000000000;i++){
       if(n/k==0) break;
       else {
           n=n/k;
           cnt++;
       }


   }
   cout << cnt+1 << endl;

}


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

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let n: usize = buf.trim_end().parse().unwrap();
    buf.clear();
    io::stdin().read_line(&mut buf).unwrap();
    let a: Vec<u64> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
    let (sum, _) = a.into_iter().fold((0, 0), |(sum, height), x| {
        let req = cmp::max(height, x);
        (sum + req - x, req)
    });
    println!("{}", sum);
}

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

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

    int ans = 0;
    rep(i, n) {
        int a; cin >> a;
        ans = __gcd(ans, a);
    }

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


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N = int(input())
H = list(map(int, str(input()).split()))

output = "Yes"
if N == 1:
    print(output)
    exit()

pre = -1
for i in range(N):
    if pre <= H[i] -1:
        pre = H[i] - 1
    elif pre <= H[i]:
        pre = H[i]
    else:
        output = "No"
        break

print(output)

Measured memory_bytes: 14396
#前後の桁数
front,back = map(int,input().split())
#テスト対象
test_code = list(input())
#数列
seikai = ["0","1","2","3","4","5","6","7","8","9"]
flag = True
 
if test_code[front] == "-":
    for x in range(front + back + 1):
        if x != front:
            if (test_code[x] in seikai) is False:
                flag = False
                break
else:
    flag = False
 
if flag == True:
    print("Yes")
else:
    print("No")

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

using namespace std;

#define PI 3.14159265358979323846264338327950L



int main(void) {

	int H, W, K, ans = 0;
	char tmp;

	cin >> H >> W >> K;

	vector<char> vec_w(W);
	vector<vector<char> > vec(H, vec_w), tmpVec;

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> tmp;
			vec[i][j] = tmp;
		}
	}

	for (int bit_h = 0; bit_h < (1 << H); ++bit_h) {
		for (int bit_w = 0; bit_w < (1 << W); ++bit_w) {
			tmpVec = vec;

			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {

					if (bit_h & (1 << i)) {
						for (int w = 0; w < W; w ++) {
							tmpVec[i][w] = 'r';
						}
					}

					if (bit_w & (1 << j)) {
						for (int h = 0; h < H; h++) {
							tmpVec[h][j] = 'r';
						}
					}
					
				}
			}

			int count = 0;
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if (tmpVec[i][j] == '#') {
						count++;
					}
				}
			}
			if (count == K) {
				ans++;
			}

		}
	}

	cout << ans << endl;
	// for(int i=0;i<H;i++){
	//     for(int j=0;j<W;j++){
	//         cout<<vec[i][j];
	//     }
	//     cout<<endl;
	// }


	return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;


void solve(string S){
  char pre=S[0];
  repf(i,1,4){  
    if(pre==S[i]){
      op("Bad")
      return;
    }pre=S[i];
  }
  op("Good")
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    string S;
    cin>>S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
A Popular Ice-cream Shop
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0219

"""
import sys


def solve(n):
    sales = [0] * 10
    for _ in range(n):
        sales[int(input())] += 1
    return ['*' * s if s else '-' for s in sales]


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        ans = solve(n)
        print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])



Measured memory_bytes: 5656
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

ll n, q;
ll A[30], B[200];
ll dp[2000];

void search(int i, int cnt) {
    dp[cnt] = 1;
    if (i == n)
        return;
    search(i + 1, cnt);
    search(i + 1, cnt + A[i]);
}

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

    cin >> n;
    memset(dp, 0, sizeof(dp));
    rep(i, n) { cin >> A[i]; }

    search(0, 0);

    cin >> q;
    rep(i, q) {
        cin >> B[i];
        if (dp[B[i]]) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3232
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
const ll m = (1e+9) + 7;

int main() {
	ll n, k = 0;
	static ll ans;
	cin >> n;
	vector<string> s;
	string s1;
	for (int i = 0; i < n; ++i) {
		cin >> s1;
		sort(s1.begin(),s1.end());
		s.push_back(s1);
	}
	sort(s.begin(), s.end());
	for (int i = 0; i < n - 1; ++i) {
		if (s[i] != s[i + 1]) {
			ans += (i - k)*(i - k + 1) / 2;
			k = i + 1;
		}
	}
	ans += (n - k - 1) * (n - k) / 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}
char a[55][55];
int h , w;
int main()
{
	cin >> h >> w;
	for(int i = 1 ; i <= h ; i++){
		for(int j = 1 ; j <= w ;j++)
			cin >> a[i][j];
	}
	for(int i = 1 ; i <= h ; i++)
	{
			for(int j = 1 ; j <= w ; j++)
				{
					if(a[i][j] == '#' && a[i+1][j]!='#' && a[i][j+1]!='#' && a[i-1][j] != '#' && a[i][j-1] != '#')
					{
						cout << "No" << endl;
						return 0;
					}
				}
		
	}
	cout << "Yes" <<endl;

	return 0;
} 



Measured memory_bytes: 256
N = int(input())
i = 2
ans = []
n = N
while n > 1:
  if i > N**0.5:
    ans.append(str(n))
    break
  if n % i == 0:
    ans.append(str(i))
    n = n // i
  else:
    i += 1
print(str(N) + ': ' + ' '.join(ans))


Measured memory_bytes: 5636
h,w=map(int, input().split())
a=list()
for _ in range(h):
    a.append(str(input()))

for i in range(len(a)):
    a[i]='#'+a[i]+'#'
a.insert(0, '#'*(w+2))
a.append('#'*(w+2))

for s in a:
    print(s)

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){

	int array[5];
	scanf("%d %d %d %d %d",&array[0],&array[1],&array[2],&array[3],&array[4]);

	for(int i=1;i<=4;i++){
		for(int k=4;k>=i;k--){
			if(array[k]>array[k-1])swap(array[k],array[k-1]);
		}
	}

	for(int i=0;i<4;i++)printf("%d ",array[i]);
	printf("%d\n",array[4]);

    return 0;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int sum=0;
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    sum+=min(x,K-x);
  }
  cout << 2*sum;
}

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

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb(x) push_back(x)
#define sz(x) x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-9

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(ch) scanf("%s",ch)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define piii(x,y,z) printf("%d %d %d",x,y,z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(x,y,z) printf("%lld %lld %lld",x,y,z)
#define ps(ch) printf("%s",ch)
#define Afridi 0
#define NL printf("\n")
#define D(x) cout << #x << " = " << x << endl
#define DD(x,y) cout << #x << " = " << x << " " << #y << " = " << y << endl
#define Max 100005
#define PI 3.141592653589793
#define FI freopen("in.txt","r",stdin)
#define FO freopen("out.txt","w",stdout)
#define mod 1000000007
#define INF (LL)1e18

typedef long long LL;
typedef unsigned long long ULL;

using namespace std;

LL bigmod(LL b,LL p)
{
    if(p == 0)return 1;
    LL my = bigmod(b,p/2);
    my*=my;
    my%=mod;
    if(p & 1)my*=b,my%=mod;
    return my;
}
int setb(int n,int pos)
{
    return n=n | (1 << pos);
}
int resb(int n,int pos)
{
    return n=n & ~(1 << pos);
}
bool checkb(int n,int pos)
{
    return (bool)(n & (1 << pos));
}

LL n,dist[Max],par[Max],s[Max];
vector <LL> g[Max];

void dfs(LL u,LL d)
{
	dist[u] = d;
	LL len = sz(g[u]),i;
	s[u] = 1;
	Rep(i,len)
	{
		LL v = g[u][i];
		if( par[u] == v )continue;
		par[v] = u;
		dfs(v,d+1);
		s[u] += s[v];
	}
}

int main()
{
	//FI;
	LL i,x,y;
	sl(n);
	rep(i,n-1)
	{
		sll(x,y);
		g[x].pb(y);
		g[y].pb(x);
	}
	dfs(1,0);
	LL m = dist[n] + 1;
	LL my = m / 2;
	my--;
	LL cur = n;
	while( my > 0 )
	{
		cur = par[cur];
		my--;
	}
	LL tot = s[cur];
	LL other = n - tot;
	/*if( n & 1 )
	{
		if( other > tot )puts("");
		else puts("");
	}
	else
	{
		if( other >= tot )puts("");
		else puts("");
	}*/
	if( other > tot )puts("Fennec");
	else puts("Snuke");
	return 0;
}


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

int main(){
    long long int n, k, d, s=100000000, ans=0;
    cin >> n >> k;
    if(n<k){
        ans = min(n, k-n);
    }
    else if(n>=k){
        d=n-(n/k)*k;
        if(d!=0){
           s=k-(k/d)*d; 
        }
        ans = min(d,s);
    }

    cout << ans << endl;
}

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

bool data[55][31];
int N;

int main() {
  
  while(cin >> N && N) {
    memset(data, false, sizeof data);
    for(int i=0; i<N; i++) {
      int k; cin >> k;
      while(k--) {
	int h; cin >> h; data[i][h] = true;
      }
    }
    
    bool flag = false;
    set<int> st[51];
    for(int i=0; i<N; i++) {
      st[i].insert(i);
    }
    
    for(int i=1; i<31; i++) {
      for(int j=0; j<N; j++) {
	if(!data[j][i]) continue;
	for(int k=j+1; k<N; k++) {
	  if(!data[k][i]) continue;
	  st[j].insert(st[k].begin(), st[k].end());
	  st[k] = st[j];
	}
	
	if(st[j].size() == N) {
	  cout << i << endl;
	  flag = true;
	  goto EXIT;
	}
      }
    }
    
  EXIT:;
    if(!flag) cout << -1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1308
// https://ynucpc.github.io/blog/2018/04/15/cp_vscode/
// http://www.atmarkit.co.jp/ait/articles/1509/08/news019.html

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rep3(i,n,m) for(ll i=(n);i<(ll)(m);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
// #define max(a, b) ((a) > (b) ? (a) : (b))
// #define min(a, b) ((a) < (b) ? (a) : (b)) 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int _stoi(string s, int tmp=10){
	istringstream stm(s);
	int res;
	stm >> res;
	return res;
}
double _stod(string s, int tmp=10){
	istringstream stm(s);
	double res;
	stm >> res;
	return res;
}
template<typename T>string to_string(const T& n){
	std::ostringstream stm;
	stm << n;
	return stm.str();
}

// 降順ソート: sort(A, A+N, greater<>());
// min: *min_element(A, A+N)
// argmin: min_element(A, A+N)-A

ll gcd(ll a, ll b){
	if (a==0){
		return b;
	}else{
		return gcd(b%a, a);
	}
}


int main(){	
	// ll A; cin >> A;
	// cout << "hello" << _stoi("14") << max({1,3}) << endl;
	ll X, Y, Z, K;
	cin >> X >> Y >> Z >> K;
	ll A[X], B[Y], C[Z];
	rep(i, X)cin >> A[i];
	rep(i, Y)cin >> B[i];
	rep(i, Z)cin >> C[i];
	ll iters[Z] = {}, AB[X*Y];
	rep(i, X)rep(j, Y){
		AB[i*Y+j] = A[i] + B[j];
	}
	sort(AB, AB+X*Y, greater<>());
	sort(C, C+Z, greater<>());
	rep(i, K){
		ll ma=0, argma;
		rep(j, Z){
			if (iters[j]<X*Y){
				if (ma < C[j]+AB[iters[j]]){
					ma = C[j]+AB[iters[j]];
					argma = j;
				}
			}
		}
		iters[argma]++;
		cout << ma << endl;
	}

}








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

int main(){
  int n; cin>>n;
  string s; cin>>s;
  string base="0123456789";
  int a=0,b=0,c=0,ans=0;
  while(a!=11){
    bool flag=false,flag2=false;
    for(int i=0;i<n-2;i++){
      if(flag) break;
      if(base[a]==s[i]){
        flag=true;
        for(int j=i+1;j<n-1;j++){
          if(flag2) break;
          if(base[b]==s[j]){
            flag2=true;
            for(int k=j+1;k<n;k++){
              if(base[c]==s[k]){
                ans++;
                break;
              }
            }
          }
        }
      }
    }
    c++;
    if(c==11){
      c=0; b++;
      if(b==11){
        a++; b=0;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0136
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int[] res = new int[6];

            int n = RInt();
            for (int i = 0 ; i < n ; i++)
            {
                double measuredValue = RDouble();
                if (measuredValue < 165) res[0]++;
                else if (measuredValue < 170) res[1]++;
                else if (measuredValue < 175) res[2]++;
                else if (measuredValue < 180) res[3]++;
                else if (measuredValue < 185) res[4]++;
                else res[5]++;
            }
             
            for (int i = 0 ; i < res.Length ; i++) Console.WriteLine("{0}:{1}", i + 1, new string('*',res[i]));
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



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

int main() {
	int a[15][15];
	int b;
	while (cin >> b, b) {
		memset(a, -1, sizeof(a));
		int x = b / 2 + 1, y = b / 2;
		a[x][y] = 1;
		for (int c = 2; c <= b * b; c++) {
			x++; y++;
			while (1) {
				if (x >= b)x -= b;
				if (y < 0)y += b;
				if (y >= b)y -= b;
				if (a[x][y] == -1) {
					a[x][y] = c;
					break;
				}
				x++; y--;
			}
		}
		for (int p = 0; p < b; p++) {
			for (int q = 0; q < b; q++) {
				printf("%4d", a[p][q]);
			}
			puts("");
		}
	}
}

Measured memory_bytes: 3148
/*Arnab's Code
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define vll vector<ll>
#define vii vector<int>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define take(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define takes(a,n,st) for(ll i=st;i<n+st;i++)cin>>a[i]
ll sum(ll a[],ll n,ll s){ for(ll i=0;i<n;i++)s+=a[i]; return s;}
#define mod 1000000009
ll power(ll x, ll y, ll p)  {  
    ll res = 1;  
    x = x % p;   
    if (x == 0) return 0;  
    while (y > 0){  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
ll v[117];
ll w[117];
void solve(){
	ll n,W,i,j,k,l,tot,ans;
	cin>>n>>W;
	for(i=0;i<n;i++){
		cin>>w[i]>>v[i];
	}	
	vector<vll> val(4, vll());
	for (i=0;i<n;i++) {
        val[w[i]-w[0]].pb(v[i]);
//      cout<<w[i]-w[0]<<" "<<v[i]<<endl;
    }
    sort(val[0].begin(),val[0].end(),greater<ll>());
//  reverse(val[0].begin(),val[0].end());
    sort(val[1].begin(),val[1].end(),greater<ll>());
//  reverse(val[1].begin(),val[1].end());
    sort(val[2].begin(),val[2].end(),greater<ll>());
//  reverse(val[2].begin(),val[2].end());
    sort(val[3].begin(),val[3].end(),greater<ll>());
//  reverse(val[3].begin(),val[3].end());
    for(i=0;i<4;i++){
    	for(j=1;j<val[i].size();j++)
    		val[i][j]+=val[i][j-1];
    }
    tot=0;
    for(i=0;i<=val[0].size();i++){
    	for(j=0;j<=val[1].size();j++){
    		for(k=0;k<=val[2].size();k++){
    			for(l=0;l<=val[3].size();l++){
    				if ((i*w[0] + j*(w[0]+1) + k*(w[0]+2) + l*(w[0]+3)) > W) {
                        continue;
                    }
                    ans=0;
                    if(i>0)
                    	ans+=val[0][i-1];
                    if(j>0)
                    	ans+=val[1][j-1];
                    if(k>0)
                    	ans+=val[2][k-1];
                    if(l>0)
                    	ans+=val[3][l-1];
                    tot=max(tot,ans);
    			}
    		}
    	}
    }
    cout<<tot<<endl;
	return;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ll t,T;
//	cin>>T;
	T=1;
	for(t=1;t<=T;t++){
//		cout<<"Case #"<<t<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 3664
s = input()
s1 = int(s[:2])
s2 = int(s[2:])

if (s1 == 0) and (s2 > 12):
    print("NA")
elif (s2 == 0) and (s1 > 12):
    print("NA")
elif (s1 <= 0) and (s2 == 0):
    print("NA")
elif (s1 > 12) and (s2 > 12):
    print("NA")
elif s2 > 12:
    print("MMYY")
elif s1 > 12:
    print("YYMM")
elif (s1 == 0) and (s2 <= 12):
    print("YYMM")
elif (s2 == 0) and (s1 <= 12):
    print("MMYY")
else:
    print("AMBIGUOUS")


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

int n, a[26];
string s;
long long ans = 1, mod = 1e9+7;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> s;
	for(int i=0; i<n; ++i){
		++a[s[i]-'a'];
	}
	for(int i=0; i<26; ++i){
		ans *= a[i] + 1;
		ans %= mod;
	}
	--ans;
	cout << ans << "\n";
}

Measured memory_bytes: 512
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
X = LI()

X_sort = sorted(X)
# X.sort()

mid = X_sort[N // 2]

for i in range(N):
    if X[i] < mid:
        print(X_sort[N // 2])
    else:
        print(X_sort[N // 2 - 1])

    


Measured memory_bytes: 32852
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int x, y;
            string[] inputArray = Console.ReadLine().Split(' ');
            x = int.Parse(inputArray[0]);
            y = int.Parse(inputArray[1]);
            Console.WriteLine(x * y);
        }
    }
}

Measured memory_bytes: 27444
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

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

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


void Main()
{
    int n;cin>>n;

    double t=0.0;
    REP(i,n){
        double a;cin>>a;
        t += 1.0/a;
    }

    cout<<(1.0/t)<<endl;

	return;
}

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

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

int main()
{
    ll nm,sm,x;
    cin >> nm >> sm;
    ll ar[nm+5];
    for(ll i=0; i<nm; i++)
    {
        cin >> ar[i];
    }
    sort(ar,ar+nm);
    ll pp=nm-sm;
    ll sum=0;
    for(ll i=0; i<pp; i++)
    {
        sum+=ar[i];
    }
    cout<<sum<<endl;
}



Measured memory_bytes: 1792
import sys
from collections import deque


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    K = int(input())
    q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
    for i in range(K):
        d = q.popleft()
        a = d % 10
        if a == 0:
            q.append(d * 10)
            q.append(d * 10 + 1)
        elif a == 9:
            q.append(d * 10 + a - 1)
            q.append(d * 10 + a)
        else:
            q.append(d * 10 + a - 1)
            q.append(d * 10 + a)
            q.append(d * 10 + a + 1)
    print(d)


if __name__ == "__main__":
    main()


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

#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()  
{ 
    FAST_INP;
    int x,y;
    cin >> x >> y;
    int a = (4*x-y)/2;
    int aa = (4*x-y)%2;
    int b = x - a;
    if( a>=0 && aa == 0 && b>=0 ) cout << "Yes\n";
    else cout << "No\n";
    return 0;
} 

Measured memory_bytes: 3648
#167
#d
n,k = map(int, input().split())
ln = list(map(int, input().split()))# まちi にいるとき次に町ln[i-1]へいく

# n,k = 10*4,10**18
# ln = list(range(2,n+1))
# ln.append(1)

visit = [0]*n 
now= 1 # 街iにいる
before =[] # ループに入る前（1回めのループ含む）
roop =[] #　ループ内
while visit[now -1] != 2:
    if visit[now -1] ==  0:
        before.append(now)
    elif visit [now-1] == 1:
        roop.append(now)
    
    visit[now -1]+= 1
    now = ln[now-1]


if k < len(before):
    print(before[k])
else :
    print(roop[((k-len(before))%len(roop)) ])
    

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

using ll=long long;

int main() {
  ll N,a=0,i;
  cin >> N;
  
  if(N%2 != 0)
    cout << 0;
  else {
    for(i=10; i<=N; i*=5)
      a += N / i;
    cout << a;
  }
  cout << endl;
}

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

int main(){
  long long int a,b,c,d,e,f,g; 
  cin >> a >> b >> c >> d >> e >> f >> g;
  long long int ans =0;
  if((a%2)  +  (d%2)  + (e%2) >= 2 && a>0 && d>0 && e>0){
    ans = ans+6;
    a--; d--; e--;
  }
  ans =ans+ 4*(a/2) + 2*b + 4 * (d/2) + 4*(e/2);
  cout << ans/2 << endl;
  return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> crd(n);

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

	for (int i = 0; i < n; i++)
	{
		for (int j = n - 1; j > i; j--)
		{
			if (crd.at(i) < crd.at(j)) swap(crd.at(i), crd.at(j));
		}
	}
	int a = 0, b = 0;
	for (int i = 0; i < n; i++)
	{
		if (i % 2) b += crd.at(i);
		else a += crd.at(i);
	}
	cout << a - b << endl;

}


Measured memory_bytes: 3608
#include<stdio.h>

int main(void){
    long a, b, k, i;

    scanf("%ld%ld%ld",&a,&b,&k);

    if(a < k){
        k = k - a;
        a = 0;
        if(b > k){
            b = b - k;
            printf("%ld %ld\n",a,b);
        }
        else{
            printf("0 0\n");
        }
    }
    else{
        a = a - k;
        printf("%ld %ld\n",a ,b);
    }

    return 0;
}

Measured memory_bytes: 128
// D.

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

using namespace std;
typedef long long LL;

int main(int argc, char* argv[]) {
	LL n, k;
	cin >> n >> k;
	vector<int> a(n), p(n, -1);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		--a[i];
	}
	int c = 0;
	for (LL t = 0; t < k; ++t) {
		c = a[c];
		if (p[c] >= 0) {
			LL f = t - p[c];
			t += max(0LL, (k - t - 1) / f) * f;
		}
		p[c] = t;
	}
	cout << (c + 1) << endl;
	return 0;
}


Measured memory_bytes: 4848
n,W=map(int,input().split())
from collections import defaultdict
WD=[list(map(int,input().split())) for _ in range(n)]
d=defaultdict(int)
d[0]=0
for w,v in WD:
    for i ,j in d.copy().items():
        if i+w <=W:
            d[w+i]=max(d[w+i],j+v)

print(max(d.values()))

Measured memory_bytes: 43760
import           Control.Applicative
import           Data.Char
import           Data.List

main :: IO ()
main = getContents >>= mapM_ (print . toArabic) . lines

toArabic :: String -> Int
toArabic = snd . foldl f (0, 0)
  where f (prev, sum) c
          | prev < toArabic' c = (toArabic' c, sum + toArabic' c - 2 * prev)
          | otherwise          = (toArabic' c, sum + toArabic' c)

        toArabic' 'M' = 1000
        toArabic' 'D' = 500
        toArabic' 'C' = 100
        toArabic' 'L' = 50
        toArabic' 'X' = 10
        toArabic' 'V' = 5
        toArabic' 'I' = 1
        toArabic' _   = 0

Measured memory_bytes: 3684
import java.util.Scanner;

class Problem {
    private int N;
    private int W;
    private int[] weights;
    private int[] values;

    Problem() {
        Scanner sc = new Scanner(System.in);

        N = sc.nextInt();
        W = sc.nextInt();

        weights = new int[N];
        values = new int[N];

        for (int i = 0; i < N; i++) {
            weights[i] = sc.nextInt();
            values[i] = sc.nextInt();
        }
    }

    long solve() {
        int V = 0;
        for (int i = 0; i < N; i++) {
            V += values[i];
        }

        long[][] dp = new long[N][V+1];

        for (int i = 0; i < N; i++) {
            dp[i][0] = 0;
            for (int v = 1; v <= V; v++) {
                dp[i][v] = W+1;
            }
        }

        for (int i = 0; i < N; i++) {
            for (int v = 1; v <= V; v++) {
                if (i == 0) {
                    if (v == values[i]) {
                        dp[i][v] = weights[i];
                    }
                } else {
                    if (v < values[i]) {
                        dp[i][v] = dp[i - 1][v];
                    } else {
                        dp[i][v] = Math.min(dp[i - 1][v], dp[i-1][v - values[i]] + (long) weights[i]);
                    }
                }
            }
        }

        long found = 0;
        for (int v = V; v > 0; v--) {
            if (dp[N-1][v] <= W) {
                found = v;
                break;
            }
        }

        return found;
    }
}

public class Main {
    public static void main(String[] args) {
        long ans = new Problem().solve();
        System.out.println(ans);
    }
}


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

// template {{{
/* vim: set foldmethod=marker: */

// constant
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const double PI = acos(-1);
#define EPS 1e-14

// typedef
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;

// input
inline int inputi(){ int x; scanf("%d", &x); return x; }
inline ll inputll(){ ll x; scanf("%lld", &x); return x; }
inline double inputd(){ double x; scanf("%lf", &x); return x; }
inline string inputs(){ string x; cin >> x; return x; }

// short
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define REPit(type, i, obj) for (type::iterator i = (obj).begin(); i != (obj).end(); i++)
#define RREPit(type, i, obj) for (type::iterator i = (obj).rbegin(); i != (obj).rend(); i++)

// container util
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define sz(obj) ((int)(obj).size())
#define sort(obj) sort(all(obj))
#define exist(obj, key) ((obj).find(key) != (obj).end())
#define clear(array) memset((array), 0, sizeof(array))

// print util
#define print(x) cout << (x) << endl
template <class T> inline void printall(vector<T> v){ REP(i, sz(v)) cout << v[i] << "\n "[i < sz(v) - 1]; }
#define dump(x) cerr << #x << ": " << (x) << endl
#define debug(x) cerr << #x << ": " << (x) << " (" << __LINE__ << ")" << endl

//template }}}

int main()
{
    int n = inputi();
    vll v(n);
    REP(i, n) v[i] = inputll();
    printf("%lld %lld %lld\n", *min_element(all(v)), *max_element(all(v)), accumulate(all(v), 0LL));

    return 0;
}

Measured memory_bytes: 1264
n, k = map(int, input().split())
d = [[0 for _ in range(k+1)] for _ in range(k+1)]
e = [[0 for _ in range(k+1)] for _ in range(k+1)]
cnt_d, cnt_e = 0, 0

for _ in range(n):
    x, y, c = input().split()
    x, y = int(x), int(y)

    res = (x // k + y // k) % 2
    if (res == 0 and c == 'B') or (res == 1 and c == 'W'):
        d[x%k+1][y%k+1] += 1
        cnt_d += 1
    else:
        e[x%k+1][y%k+1] += 1
        cnt_e += 1

for i in range(k+1):
    for j in range(k):
        d[i][j+1] += d[i][j]
        e[i][j+1] += e[i][j]

for j in range(k+1):
    for i in range(k):
        d[i+1][j] += d[i][j]
        e[i+1][j] += e[i][j]


ans = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        res_d = d[-1][-1] - d[i-1][-1] - d[-1][j-1] + 2 * d[i-1][j-1]
        res_e = e[-1][-1] - e[i-1][-1] - e[-1][j-1] + 2 * e[i-1][j-1]
        ans = max(ans,res_d + cnt_e - res_e, res_e + cnt_d - res_d)

print(ans)

Measured memory_bytes: 66524
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 

void distributeV(int parent, int current, const vector< vector<int> >& node, vector<LL>& v)
{
    for (int c : node[current]) {
        if (c != parent) {
            v[c] += v[current];
            distributeV(current, c, node, v);
        }
    }
}

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

    vector< vector<int> > node(N+1);
    for (int i = 1; i <= N-1; ++i) {
        int a, b;
        cin >> a >> b;
        node[a].push_back(b);
        node[b].push_back(a);
    }

    vector<LL> v(N+1, 0);
    for (int i = 0; i < Q; ++i) {
        int p, x;
        cin >> p >> x;
        v[p] += x;
    }

    distributeV(0, 1, node, v);

    for (int i = 1; i <= N; ++i) {
        cout << v[i] << endl;
    }

    return 0;
}


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

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

// abbreviati
#define PB(v) push_back(v)
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

// constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

// adjacency list
vector<int> to[100005];

// Graph
using Graph = vector<vector<int>>;

// Grid
int H,W;
vector<vector<int>> field;

// 4方向への移動ベクトル
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,a,b;
    cin >> n >> a >> b;
    if(n*a>=b){
        cout << b ENDL;
    }else cout << n*a ENDL;
    
    return 0;
}

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

using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	
	bool ok = 1;
	
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		
		if (x & 1) continue;
		
		if (x % 3 == 0 || x % 5 == 0) {
		}
		else ok = 0;
	}
	
	if (ok) printf("APPROVED\n");
	else printf("DENIED\n");
}


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

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int n,flag=0;
	cin >> n;
	int p[n],q[n];
	for(int i=0;i<n;i++)
		cin >> p[i];
	for(int i=0;i<n;i++)
		cin >> q[i];
	for(int i=0;i<n;i++){
		if(p[i]>q[i]){
			flag=1;
			break;
		}
		if(p[i]<q[i])break;
	}
	if(flag){
		for(int i=0;i<n;i++)
			swap(p[i],q[i]);
	}
	int c=0;
	while(1){
		flag=1;
		for(int i=0;i<n;i++){
			if(p[i]!=q[i]){
				flag=0;
				break;
			}
		}
		if(flag)break;
		next_permutation(p,p+n);
		c++;
	}
	cout << c;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()

ans = 0
c = 0
for i in range(N):
    if S[i] == 'L':
        if i > 0 and S[i - 1] == 'L':
            ans += 1
    elif S[i] == 'R':
        if i < N - 1 and S[i + 1] == 'R':
            ans += 1
    if i < N - 1 and S[i] != S[i + 1]:
        c += 1

if c % 2 == 0:
    max_K = c // 2
    ans += min(K, max_K) * 2
else:
    max_K = (c - 1) // 2
    ans += min(K, max_K) * 2
    if K > max_K:
        ans += 1
print(ans)


Measured memory_bytes: 3316
use proconio::input;
use std::collections::BTreeMap;

fn lower_bound(map: &BTreeMap<usize, usize>, target: usize) -> usize {
    *map.range(target..).next().unwrap().1
}

fn update(map: &mut BTreeMap<usize, usize>, key: &usize, value: usize) {
    let t = *map.entry(*key).or_insert(usize::max_value());
    *map.entry(*key).or_default() = t.min(value);
}

fn main() {
    input! {
        n: usize,
        q: usize,
        query: [(usize, usize); q],
    }

    let mut h_map = BTreeMap::new();
    let mut w_map = BTreeMap::new();

    h_map.insert(n-1, n);
    w_map.insert(n-1, n);

    let mut ans = 0;

    for &(c, x) in query.iter() {
        if c == 1 {
            let t = lower_bound(&h_map, x);
            if t <= 1 {
                continue;
            }
            ans += t-2;
            update(&mut w_map,&(t-1), x);
        }
        else {
            let t = lower_bound(&w_map, x);
            if t <= 1 {
                continue;
            }
            ans += t-2;
            update(&mut h_map, &(t-1), x);
        }
    }

    println!("{}", (n-2)*(n-2) - ans);
}


Measured memory_bytes: 12020
#include <bits/stdc++.h>
using namespace std;
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

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

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

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;

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

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

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
int main(){
  int n, cnt=0;
  cin >> n;
  VI s(n), l;
  bool flg = false;
  REP(i,n){
      cin >> s[i];
      cnt+=s[i];
      if(s[i]%10!=0) l.push_back(s[i]);
      if(s[i]%10!=0) flg = true;
  }
  if(l.size()!=0) sort(l.begin(), l.end());
  if(flg==false){
        cout << 0 << endl;
      }else{
          if(cnt%10==0) cout << cnt-l[0] << endl;
          else cout << cnt << endl;
      }
  
}

Measured memory_bytes: 256
#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;
#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 < 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 < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    vector<ll> d(N);
    REP(i, N) cin >> d[i];

    ll res = 0;
    REP(i, N)REP(j, N){
    	if(i<j){
    		res += d[i]*d[j];
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
 
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

 
int main(){
    //毎ターン　それぞれが　p_sum <= g_sum
    string s; cin >> s;
    int p_sum = 0; int g_sum = 0;
    int ans = 0;
    for(int i = 0; i<s.size();i++){
      if(p_sum == g_sum){
        g_sum += 1;
        if(s.at(i)=='p') ans -= 1;
      }else{
        p_sum += 1;
        if(s.at(i) == 'g') ans += 1;
      }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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;
}
const int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;

long long GCD(long long a, long long b) {
	if (a < b) {
		swap(a, b);
	}
	long long r = -1;
	while (r != 0) {
		r = a % b;
		a = b;
		b = r;
	}
	return a;
}

int main() {
	int N;
	string S;
	cin >> N >> S;
	long long r, g, b;
	r = g = b = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'R') {
			r++;
		}
		else if (S[i] == 'G') {
			g++;
		}
		else {
			b++;
		}
	}
	long long ans = r * g * b;
	for (int i = 0; i <= N - 3; i++) {
		for (int j = i + 1; j <= N - 2; j++) {
			int k = 2 * j - i;
			if (k > N - 1) {
				break;
			}
			if (S[i] != S[j] && S[i] != S[k] && S[j] != S[k]) {
				ans--;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3592
n = int(input())
if n == 1:
    print(0)
    exit()
mod = pow(10, 9) + 7
tmp = (pow(9, n, mod) * 2) % mod  - pow(8, n, mod)
if tmp < 0:
    tmp += mod
ans = (pow(10, n, mod) - tmp) % mod
if ans < 0:
    ans += mod
print(ans)


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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  if(a >= k) cout << k << endl;
  else if(a + b >= k) cout << a << endl;
  else {
    int m = k - a - b;
    cout << a - m << endl;
  }
}

Measured memory_bytes: 3580