akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto x : v){cout << x << " ";} cout << endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(vv) for(auto v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

const int MAX = 1 << 20;
bool ok[MAX];
string s;
int n;

void dfs(int i, int state, int used) {
    // cout << i << " " << state << " " << used << endl;
    if (i == n) {
        ok[state] = true;
        return;
    }

    if (s[i] == 'a' || ((used >> (s[i] - 'a')) & 1))
    {
        dfs(i + 1, state, used | (1 << (s[i] - 'a')));
    }
    if (s[i] != 'z' && !((used >> (s[i] - 'a' + 1)) & 1))
    {
        dfs(i + 1, state | (1 << i), used | (1 << (s[i] - 'a' + 1)));
    }
}

string f(int state) {
    string t;
    rep(i, n) {
        t += s[i] + ((state >> i) & 1);
    }
    return t;
}

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

    while (cin >> s, s != "#") {
        n = s.size();

        rep(i, 1 << n) {
            ok[i] = false;
        }

        dfs(0, 0, 0);

        int cnt = 0;
        vector<int> v;
        rep(i, 1 << n) {
            if (ok[i]) {
                cnt++;
                v.emplace_back(i);
            }
        }
        cout << cnt << endl;

        vector<string> vs;
        rep(i, v.size()) {
            vs.emplace_back(f(v[i]));
        }

        sort(all(vs));

        if (cnt <= 10) {
            rep(i, vs.size()) {
                cout << vs[i] << endl;
            }
        } else {
            rep(i, 5) {
                cout << vs[i] << endl;
            }
            rep2(i, (int)vs.size() - 5, vs.size()) {
                cout << vs[i] << endl;
            }
        }
    }

}

Measured memory_bytes: 5632
import java.util.Scanner;

public class Main {

	static int n, m;
	static int[] a, b;
	static boolean[] vis;
	static boolean[][] g;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		a = new int[m];
		b = new int[m];
		vis = new boolean[n];
		g = new boolean[n][n];
		for(int i = 0 ; i < m ; i++) {
			a[i] = sc.nextInt() - 1;
			b[i] = sc.nextInt() - 1;
			g[a[i]][b[i]] = g[b[i]][a[i]] = true;
		}
		int ans = 0;
		for(int i = 0 ; i < m ; i++) {
			for(int j = 0 ; j < n ; j++) vis[j] = false;
			g[a[i]][b[i]] = g[b[i]][a[i]] = false;
			dfs(0);
			boolean bridge = false;
			for(int j = 0 ; j < n ; j++) {
				if(!vis[j]) bridge = true;
			}
			if(bridge) ans++;
			g[a[i]][b[i]] = g[b[i]][a[i]] = true;
		}
		System.out.println(ans);
	}

	static void dfs(int x) {
		vis[x] = true;
		for(int i = 0 ; i < n ; i++) {
			if(!vis[i] && g[x][i]) dfs(i);
		}
	}

}

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

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

const string YES = "Yes";
const string NO = "No";
void solve(long long A, long long B, long long C) {

    if (A == B and B != C) {
        cout << YES << endl;
    } else if (B == C and C != A) {
        cout << YES << endl;
    } else if (C == A and A != B) {
        cout << YES << endl;
    } else {
        cout << NO << endl;
    }
}

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

    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#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 ld long double
#define pb push_back
#define eb emplace_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 llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
// #define M_PI 3.14159265358979323846 // CFでは定義しておく必要あり
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

void print() {
  cout << endl;
};

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
};

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i, 0, k-1) cout << vec[i] << " ";
   cout << vec[k-1] << endl;
};

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
};

template<class T, class U>
void print(pair<T,U> &p){
  cout << p.first << " " << p.second << "\n";
};

vector<int> divisor(int n) {
  vector<int> ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  // sort(All(ret));
  return (ret);
};

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

  int N; cin >> N;
  int ans = 0;
  rep(i, 1, N+1) {
    if (i % 2 == 1) {
      auto div = divisor(i);
      if (div.size() == 8) ans++;
    }
  }

  cout << ans << endl;

  return 0;
};


Measured memory_bytes: 256
import math
a,b=map(int,input().split())
ans=1
while ans>0 :
    a_ans=math.floor(ans*0.08)
    b_ans=math.floor(ans*0.1)
    if a_ans==a and b_ans==b:
        break
    elif a_ans>a or b_ans>b:
        ans=-1
        break
    else:
        ans+=1
print(ans)

Measured memory_bytes: 3060
a,b,n = map(int,input().split())


ans = (a*n)//b-a*(n//b)
if n >= 1:
    ans2 = (a*(n-1))//b - a*((n-1)//b)
else:
    ans2 = 0
if n >= 2:
    ans3 = (a*(n-2))//b - a*((n-2)//b)
else:
    ans3 = 0
if n >= 3:
    ans4 = (a*(n-3))//b - a*((n-3)//b)
else:
    ans4 = 0

if b <= n:
    ans5 = (a*(b-1))//b - a*((b-1)//b)
else:
    ans5 = 0
print(max(ans,ans2,ans3,ans4,ans5))



Measured memory_bytes: 9212
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fromIntegral . fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine
getIntListN n = map readInt <$> replicateM (fromIntegral n) BS.getLine

calc table (a : as) = do
  let index = a - 1
  point <- VUM.read table index
  VUM.write table index (point + 1)
  when (as /= []) $ calc table as

result table n' n q k = do
  point <- VUM.read table n'
  let point' = k - q + point
  if point' > 0
    then putStrLn "Yes"
    else putStrLn "No"
  when (n' < n) $ result table (n' + 1) n q k

main = do
  [n, k, q] <- getIntList
  as <- getIntListN q
  table <- VUM.replicate n 0 :: IO (VUM.IOVector Int)
  calc table as
  result table 0 (n -1) q k


Measured memory_bytes: 21372
#include <iostream>
#include <string>

using namespace std;

int main () {
    int k, s;
    cin >> k >> s;

    int cnt = 0;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            int z = s - x - y;
            if (z >= 0 && z <= k) cnt++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>




typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)
#define sz(x) int(x.size())


template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

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

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;




int main(){
    string s;
    cin>>s;
    int n=s.size();
    int ans=0;
    rep(i,n){
        if (s[i]=='+') ans++;
        else ans--;
    }
    
    cout<<ans;
    return 0;
  
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    vector<int> w(n, 0);
    for(int i = 0; i < n; i++) {
        if (s[i] == 'W') w[i]++;
    }
    for (int i = 1; i < n; i++) {
        w[i] += w[i - 1];
    }
    int ans = 10000000;
    for (int i = 0; i < n; i++) {
        int left = (i > 0 ? w[i - 1] : 0);
        int right = n - i - 1 - (w[n - 1] - w[i]);
        ans = min(ans, left + right);
    }
    
    cout << ans << endl;
    return 0;
}

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


#define ll long long
#define MOD 1000000007



int main(){
    string n;
    cin>>n;
    char j = n.at(n.size()-1);

    if(j=='2'||j=='4'||j=='5'||j=='7'||j=='9'){
        cout<<"hon"<<endl;
    }else if(j=='3'){
        cout<<"bon"<<endl;
    }else{
        cout<<"pon"<<endl;
    }
}


Measured memory_bytes: 3564
/**-------------------------
|--------From A.R.A--------|
-------------------------**/

#include <bits/stdc++.h>

#define ll            long long int
#define pb            push_back
#define ull           unsigned long long int
#define endl          "\n"
#define sz(c)         (c).size()
#define sall(c)       sort((c).begin(),(c).end())
#define rsall(c)      sort((c).rbegin(),(c).rend())
#define rev(c)        reverse((c).begin(),(c).end())
#define FOR(i,n)      for(ll i=0;i<n;i++)
#define max3(a,b,c)   max(max(a,b),c)
#define min3(a,b,c)   min(min(a,b),c)
#define input(a,i,n)  for(ll i=1;i<=n;i++){      cin>>a[i];}
#define output(a,i,n) for(ll i=1;i<=n;i++){cout<<a[i]<<" ";}

using namespace std;
int64_t R=1;
void solution(){
    char s;
    cin>>s;
    if(s-0<=90 && s-0>=65){cout<<"A"<<endl;}
    else{cout<<"a"<<endl;}
}
int main(){
    while(R--){solution();}
    return 0;
}


Measured memory_bytes: 3648
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
dp = [[0 for _ in range(w)] for i in range(h)]
if s[0][0] == "#":
  dp[0][0] = 1
for i in range(1,w):
  if s[0][i] == "#" and s[0][i-1] == "#":
    dp[0][i] = dp[0][i-1]
  elif s[0][i] == "#":
    dp[0][i] = dp[0][i-1]+1
  else:
    dp[0][i] = dp[0][i-1]
for i in range(1,h):
  if s[i][0] == "#" and s[i-1][0] == "#":
    dp[i][0] = dp[i-1][0]
  elif s[i][0] == "#":
    dp[i][0] = dp[i-1][0]+1
  else:
    dp[i][0] = dp[i-1][0]
for i in range(1,h):
  for j in range(1,w):
    if s[i][j] == "#":
      if s[i-1][j] == "." and s[i][j-1] == ".":
        dp[i][j] = min(dp[i-1][j]+1,dp[i][j-1]+1)
      elif s[i-1][j] == ".":
        dp[i][j] = min(dp[i-1][j]+1,dp[i][j-1])
      elif s[i][j-1] == ".":
        dp[i][j] = min(dp[i-1][j],dp[i][j-1]+1)
      else:
        dp[i][j] = min(dp[i-1][j],dp[i][j-1])
    else:      
      dp[i][j] = min(dp[i-1][j],dp[i][j-1])
#print(dp)
print(dp[-1][-1])

Measured memory_bytes: 42096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, p;
ll c[2];
int main(){
 cin>>n>>p;
 c[0]=1;
 for(;n--;){
  int x; cin>>x;
  if(x%2) c[0]+=c[1], c[1]=c[0];
  else c[0]*=2, c[1]*=2;
 }
 cout<<c[p]<<endl;
 return 0;
}


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

int main() {
  string s;
  int k;
  cin>>s>>k;
  vector<string>sub;
  for(int i=1;i<=k;i++){
    for(int j=0;j<s.size()-i+1;j++){
      sub.push_back(s.substr(j,i));
    }
  }
  sort(sub.begin(),sub.end());
  int now=0;
  string ss="0000";
  for(int i=0;i<sub.size();i++){
    if(sub[i]!=ss){
      ss=sub[i];
      now++;
      if(now==k){
        cout<<ss<<endl;
        break;
      }
    }
  }
}


Measured memory_bytes: 1660
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;

int main()
{
    int n;
    int s[200][3];
    int t[200]={0};
    int a=0,b=0,c=0;
    int flag[3];
    cin >> n;
    for(int i=0;i<n;++i)
    {
        cin >> s[i][0] >> s[i][1] >> s[i][2];
    }
    for(int i=0;i<n;++i)
    {
        flag[0] = 0;
        flag[1] = 0;
        flag[2] = 0;
        for(int j=0;j<n;++j)
        {
            if(i!=j && s[i][0]==s[j][0]) flag[0] = 1; 
            if(i!=j && s[i][1]==s[j][1]) flag[1] = 1; 
            if(i!=j && s[i][2]==s[j][2]) flag[2] = 1; 
        }
        if(!flag[0]) t[i] += s[i][0]; 
        if(!flag[1]) t[i] += s[i][1]; 
        if(!flag[2]) t[i] += s[i][2]; 
    }
    for(int i=0;i<n;++i) cout << t[i] << endl;
}

Measured memory_bytes: 1160
#! usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a = list(map(int, input().split()))

    ave = sum(a) / n
    ans, k = 0, 500
    for i in range(n):
        if abs(a[i]-ave) < k:
            ans = i
            k = abs(a[i]-ave)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

using namespace std;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}
 
const int mod = (int)1e9 + 7;

int a[4];
 
int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();   
	cin >> a[1] >> a[2] >> a[3];
	sort(a + 1, a + 3 + 1);
	if(!(a[1] & 1) || !(a[2] & 1) || !(a[3] & 1)) cout << 0 << endl, exit(0);
	else cout << a[1] * 1ll * a[2] << endl, exit(0);
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import re
H, W = map(int, input().split())
l = []
for i in range(H):
  a = input()
  if(len(re.findall('#', a)) != 0):
    l.append(a)
#print(l)

hh = len(l)
l2 = []
for j in range(W):
  if(l[0][j] == '.'):
    flag = 0
    for k in range(hh):
      if(l[k][j] == '#'):
        flag = 1
    if(flag == 0):
      l2.append(j)
#print(l2)

l3 = list(range(W))
#print(l3)
l4 = list(set(l3) - set(l2))
#print(l4)

for k in range(hh):
  a = ''
  for ll in l4:
   #print(l[k][ll]) 
   a = a + l[k][ll]
  print(a)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}

ll fact[400005];
ll inv[400005]; 

ll NCR(ll n, ll r){
    ll x = fact[n];
    x*=inv[r];
    x%=MOD;
    x*=inv[n-r];
    x%=MOD;
    return x;
}

int main() {
	fast();
 
    /*NA – JEONG – MO – SA – JI – MI – DA – CHAE – TZU*/
    
    ll n, k;
    cin >> n >> k;
    fact[0] = 1;
    for(ll i=1; i<400005; i++){
        fact[i] = fact[i-1]*i;
        fact[i]%=MOD;
    }
    inv[400004] = xmodpow(fact[400004], MOD-2, MOD);
    for(ll i=400003; i>=0; i--){
        inv[i] = xmod(inv[i+1]*(i+1), MOD);
    }
    ll ans = 0;
    for(ll i=0; i<=min(k, n-1); i++){
        ll x = NCR(n, i);
        ll rem = n-i;
        ll z = n-rem;
        ll mul = fact[z+rem-1];
        mul*=inv[rem-1];
        mul%=MOD;
        mul*=inv[z];
        mul%=MOD;
        mul*=x;
        mul%=MOD;
        ans += mul;
        ans%=MOD;
    }
    out(ans);
}

Measured memory_bytes: 6528
n, k = map(int, input().split())
s = input()

sc = 0
lr = 0
rl = 0

for i in range(n-1):
    c = s[i]
    nc = s[i+1]

    if c == nc:
        sc += 1
    elif c == 'L' and nc == 'R':
        lr += 1
    elif c == 'R' and nc == 'L':
        rl += 1

if rl == lr:
    dc = lr
    oc = 0
else:
    dc = min(lr, rl)
    oc = 1

if dc + oc <= k:
    print(dc*2 + oc + sc)
else:
    print(sc + k*2)

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

constexpr int mod = 1e9+7;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(500010);

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

  vector<mint> fact(m + 1, 1);

  for (int i = 0; i < m; i++) fact[i + 1] = fact[i] * (i + 1);

  mint res = 0;

  for (int k = 0; k <= n; k++) {
    mint tmp = (k % 2 == 0 ? 1 : -1);
    tmp *= comb(n, k) * (fact[m] / fact[m - k]) * (fact[m - k] / fact[m - n]);
    tmp *= fact[m - k] / fact[m - n];
    res += tmp;
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 14656
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli N=1e6+5;
lli n,left1[N],right1[N];
vector<pair<lli,lli>> v1,v2;

bool cmp(pair<lli,lli> &a, pair<lli,lli> &b)
{
    if(a.second!=b.second)
    return a.first<b.first;
    return a.second>b.second;
}

/*https://codeforces.com/blog/entry/77148?#comment-619728*/

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
    cin>>n;
    lli i,j,cur,flag=0;
    string s[n];
    
    for(i=0;i<n;i++)
    {
        cin>>s[i];
        
        cur=0;
        for(j=0;j<s[i].length();j++)
        {
            if(s[i][j]=='(') cur++;
            else if(cur)     cur--;
        }
        right1[i]=cur;
        
        cur=0;
        for(j=s[i].length()-1;j>=0;j--)
        {
            if(s[i][j]==')') cur++;
            else if(cur)     cur--;
        }
        left1[i]=cur;
    }
    
    for(i=0;i<n;i++)
    {
        if(right1[i]-left1[i]>=0) v1.push_back({left1[i], right1[i]});
        else                      v2.push_back({left1[i], right1[i]});
    }
    
    sort(v1.begin(),v1.end(),[](pair<lli,lli> a,pair<lli,lli> b){return a.first<b.first;});
    sort(v2.begin(),v2.end(),[](pair<lli,lli> a,pair<lli,lli> b){return a.second>b.second;});
    
    cur=0;
    for(i=0;i<v1.size();i++)
    {
        cur-=v1[i].first;
        if(cur<0)
        {
            cout<<"No";
            return 0;
        }
        cur+=v1[i].second;
    }
    
    for(i=0;i<v2.size();i++)
    {
        cur-=v2[i].first;
        if(cur<0)
        {
            cout<<"No";
            return 0;
        }
        cur+=v2[i].second;
    }
    
    if(cur) 
    {
        cout<<"No";
        return 0;
    }
    
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 65944
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
using namespace std;
const int mod=924844033,MAXN=2e5+10,g=5;
int last[MAXN];
struct Edge
{
    int to,nxt;
} ed[MAXN*2];
int tot=0;
int siz[MAXN],fa[MAXN];
int n;
typedef long long LL;
LL cnt[MAXN],fac[MAXN],invfac[MAXN],a[MAXN*4],b[MAXN*4],ans[MAXN*4],w[MAXN*4];
void DFT(LL a[],int n)
{
    int j=0;
    for(int i=0;i<n;i++)
    {
        if(i<j) swap(a[i],a[j]);
        int t=n>>1;
        while(j&t)
        {
            j^=t;
            t>>=1;
        }
        j^=t;
    }
    int i=1,m;
    while(i<n)
    {
        m=i;
        i<<=1;
        for(int j=0;j<n;j+=i)
        {
            for(int k=0;k<m;k++)
            {
                LL z=w[(n/i)*k]*a[j+m+k]%mod;
                a[j+m+k]=(a[j+k]-z)%mod;
                a[j+k]=(a[j+k]+z)%mod;
            }
        }
    }
}
LL qp(LL x,LL y)
{
    if(y==0) return 1;
    if(y==1) return x;
    LL t=qp(x,y>>1);
    t=t*t%mod;
    if(y&1) t=t*x%mod;
    return t;
}
void calc(LL a[],LL b[],int na,int nb,LL ans[])
{
    int n=na+nb-1,t=0;
    while((1<<t)<n)t++;
    n=1<<t;
    w[0]=1;
    w[1]=qp(g,(mod-1)/n);
    for(int i=2;i<n;i++) w[i]=w[i-1]*w[1]%mod;
    DFT(a,n);
    DFT(b,n);
    for(int i=1;n-i>i;i++) swap(w[i],w[n-i]);
    for(int i=0;i<n;i++) ans[i]=a[i]*b[i]%mod;
    DFT(ans,n);
    LL invn=qp(n,mod-2);
    for(int i=0;i<n;i++) ans[i]=(ans[i]*invn%mod+mod)%mod;
}
void addedge(int u,int v)
{
    ed[++tot].to=v;
    ed[tot].nxt=last[u];
    last[u]=tot;
}
void dfs(int x)
{
    siz[x]=1;
    for(int i=last[x];i>0;i=ed[i].nxt)if(ed[i].to!=fa[x])
    {
        fa[ed[i].to]=x;
        dfs(ed[i].to);
        siz[x]+=siz[ed[i].to];
        cnt[siz[ed[i].to]]--;
        cnt[n-siz[ed[i].to]]--;
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        addedge(u,v);addedge(v,u);
    }
    memset(cnt,0,sizeof cnt);
    cnt[n]=n;
    fa[1]=0;
    dfs(1);
    fac[0]=1;
    for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
    invfac[n]=qp(fac[n],mod-2);
    for(int i=n-1;i>=0;i--) invfac[i]=invfac[i+1]*(i+1)%mod;
    memset(a,0,sizeof a);
    memset(b,0,sizeof b);
    for(int i=1;i<=n;i++) a[i-1]=cnt[i]*fac[i]%mod;
    for(int i=0;i<n;i++) b[i]=invfac[n-1-i];
    memset(ans,0,sizeof ans);
    calc(a,b,n,n,ans);
    for(int i=n-1;i<=2*n-2;i++) printf("%d\n",int(ans[i]*invfac[i-n+2]%mod));
    return 0;
}


Measured memory_bytes: 42624
use text_io::*;

fn main() {
    let n: usize = read!();
    let m: usize = read!();
    let x: usize = read!();
    
    let mut books = vec![vec![]; n];
    let mut costs = vec![];
    for i in 0..n {
        let c: usize = read!();
        costs.push(c);
        for _ in 0..m {
            let a: usize = read!();
            books[i].push(a);
        }
    }
    
    let mut min = vec![];
    
    for i in 0..1 << n {
        let mut cost = 0;
        let mut vec = vec![0; m];
        for j in 0..n {
            if (1 << j) & i == 0 {
                cost += costs[j];
                for k in 0..books[j].len() {
                    vec[k] += books[j][k];
                }
            }
        }
        if vec.iter().all(|&y| y >= x) {
            min.push(cost);
        }
    }
    
    println!("{}", min.iter().min().map(|&y| y as isize).unwrap_or(-1));
}


Measured memory_bytes: 2188
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;
int x,y,z,n,f=0;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>y;
		
		if(y%2==0)
		{
			if( y%3!=0 && y%5!=0) f=1; 		
		}
		
	}
	if(f==0) cout<<"APPROVED";
	else cout<<"DENIED";
	return 0;
}

Measured memory_bytes: 3104
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>

using namespace std;
using ll = long long;

#define INF 1e9

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n;
  while(cin >> n && n){
    vector<vector<vector<int>>> dp(n+1, vector<vector<int>>(50001, vector<int>(4, INF)));
    vector<int> point(n+1);
    vector<int> times(n+1);
    point[0] = 0;
    times[0] = 0;
    dp[0][0][0] = 0;
    int i, p, t;
    bool flag;
    for(i = 0; i < n; i++){
      cin >> p >> t;
      point[i+1] = p;
      times[i+1] = t;
      flag = false;
      for(int j = 0; j < 4; j++){
        if(times[i] + point[i]*(j+1) + p <= t && dp[i][times[i]][j] != INF){
          flag = true;
          dp[i+1][t][1] = min(dp[i+1][t][1], dp[i][times[i]][j] + point[i] + p);
        }
      }
      for(int j = 0; j < 3; j++){
        if(times[i] + abs(p - point[i]) * (j+1) <= t && dp[i][times[i]][j] != INF){
          flag = true;
          dp[i+1][t][j+1] = min(dp[i+1][t][j+1], dp[i][times[i]][j] + abs(p - point[i]));
        }
      }
      if(!flag) break;
    }

    if(!flag){
      i++;
      cout << "NG" << ' ' << i << endl;
      for(i; i < n; i++) cin >> p >> t;
    }
    else{
      int ans = dp[n][times[n]][0];
      for(i = 1; i < 4; i++) ans = min(ans, dp[n][times[n]][i] + point[n]);
      cout << "OK" << ' ' << ans << endl;
    }
  }
  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}



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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i + 1 < s.size(); i++) {
    if (s[i] != s[i + 1]) ans++;
  }

  cout << ans << "\n";
  return 0;
}


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

int main(){
    long long n;
    cin >> n;
    long long m=pow(10,12);
    for(long long i=1;i<=sqrt(n);i++){
        if(n%i==0)m=min(i-1+(n/i)-1,m);
    }
    cout << m;
    return 0;
}

Measured memory_bytes: 256
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		
		System.out.println(LocalDate.parse(s, DateTimeFormatter.ofPattern("yyyy/MM/dd", Locale.JAPAN)).compareTo(LocalDate.of(2019, 4, 30)) <= 0 ? "Heisei" : "TBD");
	}
	
}


Measured memory_bytes: 29012
a, b, c = map(int,input().split())
if a > b + c:
    if b >= c:
        print(str(c) +" "+ str(0))
    else:
        print(str(b) +" "+ str(0))
elif a == b and a == c:
    print(str(a)+" "+str(a))
elif a< b+c:
    if b >= c:
        print(str(c) +" "+ str(-a + (b+c)))
    else:
        print(str(b) +" "+ str(-a+(c+b)))
elif a == b+c:
    if b >= c:
        print(str(c) +" "+ str(-a + (b+c)))
    else:
        print(str(b) +" "+ str(-a+(c+b)))
elif a == b or a==c:
    if b >= c:
        print(str(c) +" "+ str(0))
    else:
        print(str(b) +" "+ str(0))
elif a ==b ==c:
    print(str(b)+" "+str(0))

Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc079/tasks/abc079_d?lang=en

#include <bits/stdc++.h>

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {
  int n;
  scanf("%d", &n);
  int primes[n+1] = {0};

  for (int i=2; i<=n; i++) {
    int x = i;
    for (int j=2; j<=x; j++) {
      while (x % j == 0) {
        x /= j;
        primes[j]++;
      }
    }
  }

  ll ans = 1;
  ll mod = 1e9 + 7;
  for (int i=0; i<n+1; i++) {
    if (primes[i] == 0)
      continue;
    ans = (ans * (primes[i] + 1)) % mod;
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int h = 1;
		int w = 1;
		StringBuilder sb = new StringBuilder();
		while (true) {
			h = scan.nextInt();
			w = scan.nextInt();
			if (h != 0 && w != 0) {
				for (int i = 0; i < w; i++) {
					sb.append("#");
				}
				sb.append("\n");
				for ( int j = 0; j < h - 2; j++) {
					sb.append("#");
					for (int i = 0; i < w - 2; i++) {
						sb.append(".");
					}
					sb.append("#");
					sb.append("\n");
				}
				for (int i = 0; i < w && h >= 2; i++) {
					sb.append("#");
				}
				sb.append("\n");
				sb.append("\n");
			}else {
				break;
			}
		}
		System.out.print(sb);
	}
}

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

int main(){

    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    vector<int> d(n+1);
    for (int i=0; i<n; i++){
        cin >> l.at(i);
    }

    d.at(0) = 0;
    int ans;
    for (int i=1; i<n+1; i++){
        d.at(i) = d.at(i-1) + l.at(i-1);
        if (d.at(i) > x){
            ans = i;
            break;
        }
    }

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

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

int gcd(int x, int y);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }


int main() {
    string s;
    cin >> s;
    int ans = 0;
    int flag = s[0];
    for (int i = 1; i < s.size(); i++) {
        flag += s[i];
        if (flag == '0' + '1') {
            ans++;
            s.erase(s.begin() + i - 1);
            s.erase(s.begin() + i - 1);
            i -= 2;
            if (s.size() == 0 || s.size() == 1)
                break;
            if (i == -1)
                i = 0;
            flag = s[i];
        }
        else {
            flag = s[i];
        }
    }
    cout << ans * 2 << endl;
    return 0;
}
/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

Measured memory_bytes: 512
import bisect
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(0)

S = str(input())
T = str(input())
N = len(S)
cou = int(0)
cur = int(0)
move = int(0)
S_map = [[]for _ in range(26)]

for i in range(N):
    S_map[ord(S[i])-97].append(i+1)
for i in range(N):
    S_map[ord(S[i])-97].append(N+i+1)

for c in T:
#    print(cur)
    if S_map[ord(c)-97]==[]:
        ans = -1
        break
    move = bisect.bisect_left(S_map[ord(c)-97],cur+1)
    cur = S_map[ord(c)-97][move]
    if cur>=N:
        cou += 1
        cur -= N

if ans==0:
    ans = cou*N + cur

print(ans)

Measured memory_bytes: 49144
/**
 * The man who codes no bugs
 * McCheng is the man studying Maths in CUHK with IQ200
 * @author McCheng
 */

#include <bits/stdc++.h>
#define int long long
using namespace std;

class BMixJuice {
public:
    static constexpr int kStressCount = 0;
    static void generateTest(ostream& test) {}
	void solve(istream& cin, ostream& cout) {
int n,k;
cin>>n>>k;
        vector<int> a(n);
        for (int i = 0; i <n; i++) {
            cin >> a[i];
        }
        sort(a.begin(), a.end());
        int cnt=0;
        for (int j = 0; j < k; j++) {
            cnt+=a[j];
        }
        cout<<cnt;
	}
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream &in(cin);
    ostream &out(cout);
    out << fixed;
    out.precision(20);
    BMixJuice solver;
    solver.solve(in, out);
}


Measured memory_bytes: 3612
import collections
n=int(input())
a=collections.Counter([str(input()) for _ in range(n)])
m=int(input())
b=collections.Counter([str(input()) for _ in range(m)])
ans=0
for k,v in a.items():
  if b.get(k) is None:
    ans=max(ans,v)
  else:
    ans=max(ans,v-b.get(k))
print(ans)

Measured memory_bytes: 3316
parseInt(x) = parse(Int,x)

function main()
  A,B = map(parseInt,split(readline()))
  if A < B
    r = div(B-A,A-1)
    rem(B-A,A-1) == 0 ? c=r+1 : c=r+2
  else
    B == 1 ? c = 0 : c = 1
  end
  println(c)
end

main()

Measured memory_bytes: 172848
#include <stdio.h>
#include <string.h>
int main(void){
   char s[11], t[12];
   scanf("%s", s);
   scanf("%s", t);

   int n;
   n = strlen(s);

   for(int i = 0; i < n; i++){
       if(s[i] != t[i]){
           printf("No");
           return 0;
       }
   }

   printf("Yes");
}

Measured memory_bytes: 1688
X,Y,Z,K=[int(i) for i in input().split(" ")]
A=[int(i) for i in input().split(" ")]
B=[int(i) for i in input().split(" ")]
C=[int(i) for i in input().split(" ")]
 
AB=[]
 
A=sorted(A,reverse=True)[:K:]
B=sorted(B,reverse=True)[:K:]
C=sorted(C,reverse=True)[:K:]
for a in A:
    for b in B:
        AB.append(a+b)
 
AB=sorted(AB,reverse=True)[:K:]
 
ABC=[]
for ab in AB:
    for c in C:
        ABC.append(ab+c)
 
ABC=sorted(ABC,reverse=True)[:K:]
 
 
for abc in ABC:
    print(abc)

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

set<int> edges[100000];
int vis[100000];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    for(int i=1;i<n;++i){
        int a, b;
        cin >> a >> b;
        edges[a].insert(b);
        edges[b].insert(a);
    }
    queue<int> q;
    q.emplace(0);
    vis[0] = 1;
    while(!q.empty()){
        int v = q.front();
        q.pop();
        if(edges[v].size() == 2){
            vis[v] = -1;
            int u[2] = { *edges[v].begin(), *edges[v].rbegin() };
            edges[u[0]].erase(v); edges[u[0]].insert(u[1]);
            edges[u[1]].erase(v); edges[u[1]].insert(u[0]);
            if(vis[u[0]] == 0){ vis[u[0]] = 1; q.emplace(u[0]); }
            if(vis[u[1]] == 0){ vis[u[1]] = 1; q.emplace(u[1]); }
        }else{
            for(auto u: edges[v]){
                if(vis[u] == 0){ vis[u] = 1; q.emplace(u); }
            }
        }
    }
    int u, v;
    for(v=0; edges[v].size()!=1 || vis[v]<0; ++v);
    u = *edges[v].begin();
    if(edges[u].size() == 1){ cout << 1 << endl; return 0; }
    int ans = edges[u].size() - 1;
    queue<pair<int, int>> qq;
    for(int nx: edges[u]){ if(nx != v) qq.emplace(nx, u); }
    while(!qq.empty()){
        auto p = qq.front();
        qq.pop();
        if(edges[p.first].size() == 1) continue;
        bool f = false;
        for(int nx: edges[p.first]){
            if(nx == p.second) continue;
            if(edges[nx].size() == 1) f = true;
            else qq.emplace(nx, p.first);
        }
        ans += edges[p.first].size() - 2;
        if(f) --ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15616
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

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

const int maxN = 21;

int n, k, i, j, p, limit, bit, mask, nxt, aux, aux_bits;
char s[1 << maxN];
vector<int> data[maxN][maxN]; //! fixed bits, total bits
vector<int> emp;

void print_nr(int bits, int j) {
    for (bits--; bits >= 0; bits--) {
        printf("%d", (j >> bits) & 1);
    }
}

int main()
{
   // freopen("test.in","r",stdin);

    scanf("%d%d\n", &n, &k);
    for (i = 0; i <= n; i++) {
        scanf("%s\n", s);
        limit = 1 << i;
        
        emp = vector<int>(limit, 0);
        for (j = 0; j <= i; j++)
            data[j][i] = emp;

        for (j = 0; j < limit; j++)
            data[0][i][j] = s[j] - '0';
    }

    for (int bts = 0; bts <= n; bts++) {
        mask = (1 << bts) - 1;

        for (i = bts + 1; i <= n; i++) {
           int limit = (1 << i);

           for (j = 0; j < limit; j++) {
                data[bts][bts][j & mask] += data[bts][i][j];
                
                for (nxt = 0; nxt < 2; nxt++) {
                    aux = j;
                    aux_bits = i;

                    while (((aux >> bts) & 1) != nxt) {
                        aux = (aux & mask) | ((aux >> (bts + 1)) << bts);
                        if(--aux_bits == bts) break;
                    }

                    if (aux_bits != bts)
                        data[bts + 1][aux_bits][aux] += data[bts][i][j];
                }
           }
        }
    }

    for (i = n; i >= 1; i--) {
        limit = (1 << i);
        for (j = 0; j < limit; j++) {
            if (data[i][i][j] < k) continue;
            print_nr(i, j);
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 171884
#include <bits/stdc++.h>
using namespace std;
#define N 200005
#define mod 1000000007
#define pp pair<ll,ll>
typedef long long int ll;
typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++)    
void fastIO(void);
 
void decimal(int);
ll modmulti(ll, ll, ll);
ll modadd(ll, ll, ll);
ll modpower(ll, ll, ll);
ll gcd(ll, ll );
ll modinv(ll, ll);
 

int main()
{
  // decimal(1);
   fastIO();
   ll n;
   cin>>n;
   ll a[n],b[n-1];
   rep(i,n-1) cin>>b[i];
   a[0] = b[0];
   rep1(i,n-1) a[i] = min(b[i-1],b[i]);
   a[n-1] = b[n-2];
   ll sum = 0;
   rep(i,n) sum+=a[i];
   cout<<sum<<endl;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b, ll m){
   return ((a%m)*(b%m))%m;
}
ll modadd(ll a, ll b, ll m){
   return ((a%m)+(b%m)+m)%m;
}
ll modpower(ll a, ll n, ll m){
   if(n==0)
      return 1;
   ll result = 1;
   while(n>0){
      if(n%2==1)
         result = modmulti(result,a,m);
      a = modmulti(a,a,m);
      n = n/2;
   }
   return result;
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a, ll m){
   return modpower(a,m-2,m);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int p[1000001];
int n=1000000;
void ethos(){
    p[0]=1;
    p[1]=1;
    for (int i = 2;i<=n;i++)
    if (p[i]==0){
        for (int j=i*2;j<=n;j+=i) p[j]=1;
    }
}
int main(){
    ethos();
	int x;
	cin>>x;
	while(p[x++]);
	cout<<x-1;
}


Measured memory_bytes: 4096
#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(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (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(long long N, long long M, std::vector<long long> A){
    multiset<ll> s;
    rep(i,N){
        s.insert(-A[i]);
    }
    ll ans=0;
    rep(i,M){
        ll tmp=*(s.begin());
        tmp/=2;
        s.erase(s.begin());
        s.insert(tmp);
    }
    for(auto it=s.begin();it!=s.end();it++){
        //op(*it)
        ans+=*it;
    }
    op(-ans)
}

// 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(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <vector>


int main(int argc, char **argv){
	int n = 0;
	int m = 0;
	int l = 0;
	std::vector<std::vector<long> > A;
	std::vector<std::vector<long> > B;

	std::cin >> n >> m >> l;
	A.resize(n);
	B.resize(m);
	for(int r = 0; r < n; r++){
		A[r].resize(m, 0);
	}
	for(int r = 0; r < m; r++){
		B[r].resize(l, 0);
	}

	for(int r = 0; r < n; r++){
		for(int c = 0; c < m; c++){
			std::cin >> A[r][c];
		}
	}
	for(int r = 0; r < m; r++){
		for(int c = 0; c < l; c++){
			std::cin >> B[r][c];
		}
	}

	for(int r = 0; r < n; r++){
		for(int c = 0; c < l; c++){
			long v = 0;
			for(int k = 0; k < m; k++){
				v += A[r][k] * B[k][c];	
			}
			std::cout << v;
			if(c < l - 1){
				std::cout << " ";
			}
		}
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3200
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<tuple>
using namespace std;


typedef pair<int, int> P;
typedef long long ll;

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

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

	char a = 'A';

	rep(i, s.length()){
		s[i] = ((s[i] - a) + n) % 26 + a;
	}

	cout << s<< endl;


}

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

int main() {
  int a, b;
  cin >> a >> b;
  if ( a != a / 2 * 2 && b != b / 2 * 2 ) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}


Measured memory_bytes: 256
while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if (i+j)%2 == 0:
                print("#",end = "")
            else:
                print(".",end = "")
        print()

    print()


Measured memory_bytes: 7004
n  = int(input())
c = list(input())


rcnt = c.count('R')
wcnt = c.count('W')

ans = 0
if set(c) == {'R'} or set(c) == {'W'}:
    print(0)
else:
    cnt = 0
    for i in range(rcnt):
        if c[i] == 'R':
            cnt += 1
    
    print(rcnt - cnt)


Measured memory_bytes: 10572