akhauriyash/Code-Regression huggingface dataset:
import math
N,A,B=map(int,input().split())
lst=list(map(int,input().split()))
lst.sort()
a=lst[-A:]
print(sum(a)/A)
b=lst.count(a[0])
c=a.count(a[0])
if c!=A:
    print(int(math.factorial(b)/(math.factorial(c)*math.factorial(b-c))))
else:
    l=[]
    i=min([b-c,B-A])
    for k in range(0,i+1):
        l.append(math.factorial(b)/(math.factorial(c+k)*math.factorial(b-c-k)))
    print(int(sum(l)))

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

int main() {
    string Sd, T; cin >> Sd >> T;
    int ts = T.size();
    bool restorable = false;

    if (ts > Sd.size()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    /*
    int i = Sd.size() - 1;
    while (i >= 0) {
        // cout << Sd[i] << T[ts-1] << endl;
        if (restorable && Sd[i] == '?') {
            S[i] = 'a';
            i -= 1;
        } else if (i >= (ts-1) && (Sd[i] == T[ts-1] | Sd[i] == '?')) {
            bool match = true;
            for (int j = -1; j > -ts; --j) {
                if (Sd[i+j] == T[ts-1+j] | Sd[i+j] == '?') {
                    continue;
                } else {
                    match = false;
                }
            }
            if (match) {
                // Sの対象領域を置き換え
                for (int j = 0; j > -ts; --j) {
                    S[i+j] = T[ts-1+j];
                }
                restorable = true;
                i -= ts;
            } else {
                i -= 1;
            }
        } else {
            i -= 1;
        }
    }
    */
    string minS(Sd.size(), 'z');

    rep(i, Sd.size()-ts+1) {
        string S = Sd;
        // マッチングを探す
        if (Sd[i] == T[0] | Sd[i] == '?') {
            bool match = true;
            for (int j=1; j<ts; ++j) {
                if (Sd[i+j] == T[j] | Sd[i+j] == '?') {
                    continue;
                } else {
                    match = false;
                    break;
                }
            }
            if (match) {
                restorable = true;
                // matchしていれば、minSを更新
                rep(j, ts) {
                    S[i+j] = T[j];
                }
                rep(j, S.size()) {
                    if (S[j] == '?') {
                        S[j] = 'a';
                    }
                }
                minS = min(minS, S);
            }
        }
    }
    if (restorable){
        cout << minS << endl;
    } else {
        cout << "UNRESTORABLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
ZIP = lambda: zip(*(MAP() for _ in range(n)))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
   S = INPUT()

   print("Yes" if S[2] == S[3] and S[4] == S[5] else "No")


if __name__ == '__main__':
    main()


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

using namespace std;

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

int main() {
    ll n, m, i, j, k;
    cin >> n >> m;
    ll ret = 0;
    for(i=0;i<n;i++){
        cin >> k;
        if(k>=m)ret++;
    }
    cout << ret << endl;
    return 0;
}

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

numAppeared = [0] * (N+1)

for i in A:
    numAppeared[i] += 1

numAppeared.sort( reverse=True )

print( sum( numAppeared[i] for i in range(K,N) ) )

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

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

ll modpow(ll a, ll n, ll m = MOD) {
    ll ret = 1;
    ll now = a;
    while (n > 0) {
        if (n % 2 == 1) ret = ret * now % m;
        now = now * now % m;
        n /= 2;
    }
    return ret;
}

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    map<ll, ll> mp;
    rep(i, n) {
        ll now = a[i];
        for (int d = 2; d <= sqrt(now); d++) {
            if (now % d > 0) continue;
            ll cnt = 0;
            while (now % d == 0) {
                cnt++;
                now /= d;
            }
            chmax(mp[d], cnt);
        }
        if (now > 1) {
            chmax(mp[now], 1LL);
        }
    }

    ll l = 1;
    for (auto p : mp) {
        l *= modpow(p.first, p.second);
        l %= MOD;
    }

    ll ans = 0;
    rep(i, n) {
        ans += l * modinv(a[i]);
        ans %= MOD;
    }
    cout << ans << endl;
}

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

string dfs(string s, string t, int i, int sum){
  if(i==4 && sum == 7) {
    t = t + "=7";
    return t;
  }
  else if(i==4) return "";
  else if(i==0){
    char o = s.at(i);
    int a = o - '0';
    string p = t + s.at(i);
    string m = t + s.at(i); 
    return dfs(s, p, i+1, sum+a) + dfs(s, m, i+1, sum-a);
  }
  else{
    char o = s.at(i);
    int a = o - '0';
    string p = t + "+" + s.at(i);
    string m = t + "-" + s.at(i); 
    return dfs(s, p, i+1, sum+a) + dfs(s, m, i+1, sum-a);
  }
}

int main(){
  /*
  int n, i, j;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  */
 string s;
 cin >> s;
 string g = dfs(s, "", 0, 0);
 rep(i, 9) cout << g.at(i);
 cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.14159265358979323846;

void solve() {
    ll n;
    cin >> n;
    string ans;
    ll a = n % 10;
    if(a == 2 || a == 4 || a == 5 || a == 7 || a == 9) ans = "hon";
    else if(a == 3) ans = "bon";
    else ans = "pon";
    cout << ans << endl;
    return;
}

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

Measured memory_bytes: 3656
#include <iostream>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int l = s.size();
  int ok = false;
  for (int i = l - 1; i >= 0; --i) {
    string u = s.substr(i) + s.substr(0, i);
    if (t == u) {
      ok = true;
      break;
    }
  }
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

	ll n, m;
	cin >> n >> m;
	vll a(m);
	ll sum = 0;
	for (ll i = 0; i < m; i++) {
		cin >> a[i];
		sum += a[i];
	}
	if (sum <= n) cout << n - sum << endl;
	else cout << -1 << endl;
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define ll long long
#define BUF 1e5
#define INF 1 << 30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

int main() {
    cin >> N;
    vector<int> a(N);
    vector<int> mem;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    mem.push_back(a[0]);
    for (int i = 1; i < N; i++) {
        auto it = lower_bound(mem.rbegin(), mem.rend(), a[i]);
        int ind = mem.rend() - it - 1;
        if (ind == mem.size() - 1) {
            mem.push_back(a[i]);
        } else {
            mem[ind + 1] = a[i];
        }
    }
    cout << mem.size() << endl;
}

Measured memory_bytes: 1276
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    *a,=map(int,open(0).read().split())
    print((min(a[:2])*a[2])+max(0,(a[0]-a[1]))*a[3])
if __name__ == '__main__':
    main()

Measured memory_bytes: 3572
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
const int INF = 1e9;  int f = 0;
vector<int> v;long long int dp[100011]; int a[100010];
long long int h[100010]; long long int n, m;
int main() {
	cin >> n; string s;
	cin >> s;
	string t, m; int j = 0;
	if (n % 2 == 0) {
		rep(i, n / 2) {
			if (s[i] != s[i + (n / 2)]) {
				j = 3;
				break;
			}
		}
	}
	else j = 3;
	if (j == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
uses Math;
var
	N,K,i,j:Longint;
	x,y,c:Array[1..60]of Longint;
	rr:Array[1..60]of double;
	L,R,M,a,t,d,ri,rj,yy:double;
	flag:Boolean;
function count(tx,ty:double):Boolean;
var i,cnt:Longint;
begin
	cnt:=0;
	for i:=1 to N do if sqr(X[i]-tx)+sqr(Y[i]-ty)<sqr(rr[i])+0.000000001 then begin
		inc(cnt);
		if cnt=K then begin
			count:=True;
			exit;
		end;
	end;
	count:=False;
end;
begin
	read(N,K);
	for i:=1 to N do read(x[i],y[i],c[i]);
	L:=0;
	R:=200000;
	while R-L>0.000001 do begin
		M:=(L+R)/2;
		for i:=1 to N do rr[i]:=M/c[i];
		flag:=False;
		for i:=1 to N do begin
			if count(X[i],Y[i])then begin
				flag:=True;
				break;
			end;
		end;
		if not flag then begin
			for i:=2 to N do begin
				for j:=1 to i-1 do begin
					d:=sqr(X[i]-X[j])+sqr(Y[i]-Y[j]);
					ri:=rr[i];
					rj:=rr[j];
					yy:=4*sqr(ri)*d-sqr(sqr(ri)+d-sqr(rj));
					if yy<0 then continue;
					a:=arctan2(sqrt(yy),sqr(ri)+d-sqr(rj));
					t:=arctan2(Y[j]-Y[i],X[j]-X[i]);
					if count(X[i]+ri*cos(t+a),Y[i]+ri*sin(t+a)) then flag:=True
					else if count(X[i]+ri*cos(t-a),Y[i]+ri*sin(t-a))then flag:=True;
					if flag then break;
				end;
				if flag then break;
			end;
		end;
		if flag then R:=M else L:=M;
	end;
	writeln(R:0:9);
end.


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

using namespace std;
vector<string> selection_sort(vector<string> v);
vector<string> bubble_sort(vector<string> v);
void print(vector<string> v);

int main(){
    int n; cin >> n;
    vector<string> v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    vector<string> b = bubble_sort(v);
    print(b);
    cout << "Stable" <<endl;
    vector<string> s = selection_sort(v);
    print(s);
    if(s==b){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }

    return 0;
}
vector<string> bubble_sort(vector<string> v){
    string temp;
    for(int i=0; i<v.size(); i++){
        for(int j=v.size()-1; j>i; j--){
            if( v[j-1][1]  > v[j][1]){
                temp = v[j-1];
                v[j-1] = v[j];
                v[j] = temp;
            }
        }
    }
    return v;
}
vector<string> selection_sort(vector<string> v){
    string temp;
    for(int i=0; i<v.size(); i++){
        int m = i;
        for(int j=i+1; j<v.size(); j++){
            if( v[j][1] < v[m][1] ) m=j;
        }
        if(i!=m){
            temp = v[i];
            v[i] = v[m];
            v[m] = temp;
        }
    }
    return v;
}

void print(vector<string> v){
    for(int i=0;i<v.size();i++) cout<< v[i] << " \n"[i==v.size()-1];
}



Measured memory_bytes: 3208
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.first+a.second > b.first+b.second; }

signed main() {
  SS(ll,a,b,c,k)
  if(a>=k){
    p(k);
  }else{
    k-=a;
    if(b>=k){
      p(a);
    }else{
      k-=b;
      p(a-k);
    }
  }
}

Measured memory_bytes: 3696
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

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

int main(void) {
    int x;
    int a;
    int b;
    cin >> x >> a >> b;
    if (b - a <= 0) {
        cout << "delicious" << endl;    
    } else if (b - a <= x) {
        cout << "safe" << endl;    
    } else {
        cout << "dangerous" << endl;    
    }
    return 0;
}



Measured memory_bytes: 256
import sys

def main():
  input = sys.stdin.readline().rstrip

  W, H, x, y, r = map(int, input().split())
  if x - r < 0 or W < x + r or y - r < 0 or H < y + r:
    print('No')
  else:
    print('Yes')

if __name__ == '__main__':
  main()



Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;


string S;
string res;

void dfs(int i, string ans, int n){
    
    if (i == 3) {
        if(n == 7) res = ans;
        
    }else{
        dfs(i+1, ans + "+" + S[i+1], n+(S[i+1]-'0'));
        dfs(i+1, ans + "-" + S[i+1], n-(S[i+1]-'0'));
    }
    
}



int main()
{
    
    cin >> S;
    
    res = S[0];
    
    dfs(0, res, S[0]-'0');
    
    cout << res + "=7" << endl;
    
    return 0;
}



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

using namespace std;

int main() {
  int N;
  long int *A;
  long int *B;
  long int tmp,counter=0;
  int i;
  

  cin >> N; 

  A = new long int[N];
  B = new long int[N];  

  for(i=0; i<N; i++){
    scanf("%ld",&A[i]);
    scanf("%ld",&B[i]);    
  }
  
  for(i=N-1;i>=0;i--){
    tmp = (A[i]+counter)%B[i];
    if(tmp > 0)
      counter += B[i]-tmp;
  }
  cout << counter << endl;
  return 0;
}

Measured memory_bytes: 1792
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0

for i in range(A + 1):
    for j in range(B + 1):
        for k in range(C + 1):
            if 500*i+100*j+50*k == X:
                count += 1
print(count)

Measured memory_bytes: 3060
N,X=map(int,input().split())
L=[int(x) for x in input().split()]
D=[0]*(N+1)
for i in range(1,N+1):
    D[i]=D[i-1]+L[i-1]
ans=0
for d in D:
    if d<=X:
        ans+=1
print(ans)


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

constexpr int MOD = 998244353;
constexpr int MAX = 200200;

template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(long long e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e % 2 == 0) {p = (p * p) % mod; e /= 2;}
            else {a = (a * p) % mod; e--;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

template<int mod> struct Combination {
    vector<ModInt<mod>> fact, ifact;
    Combination(int n) : fact(n+1), ifact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i);
        ifact[n] = fact[n].inverse();
        for (int i = n; i > 0; i--) ifact[i - 1] = ifact[i] * i;
    }
    ModInt<mod> operator() (int n, int r) {
        if (r < 0 or r > n) return 0;
        return fact[n] * ifact[n-r] * ifact[r];
    }
    const ModInt<mod> &operator[] (int i) const {
        return fact[i];
    }
};

int main() {
	Combination<MOD> binom(MAX);
	int n, m, k;
	cin >> n >> m >> k;
	
	ModInt<MOD> ans = 0, val = m - 1;
	for (int x = 0; x <= k; x++) {
		ans += val.pow(n - x - 1) * m * binom(n - 1, n - x - 1);
	}
	
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 4664
N = int(input())
A = list(map(int,input().split()))
Q = int(input())

SA = sum(A)
CA = [0]*(10**5+1)
for i in range(N):
    CA[A[i]]+=1

for i in range(Q):
    B,C = list(map(int,input().split()))
    NB = CA[B]
    NC = CA[C]
    SA = SA - NB*B + NB*C
    CA[B] = 0
    CA[C] += NB
    print(SA)

Measured memory_bytes: 85488
lis=[]

while True:
	n,x=[int(x) for x in input().split()]
	if n==0 and x== 0:
		break
	lis.append([n,x])


for v in lis:
	n=v[0]
	x=v[1]
	# nums=lis(range(1,n+1))
	count=0
	for j in range(1,n-2 +1):
		for k in range(j+1,n-1 +1):
			for l in range(k+1,n +1):
				if j+k+l==x:
					count+=1

	print(count)



Measured memory_bytes: 5600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, l; cin >> n >> l;
    vector<int> a(n); rep (i, n) a[i] = l + i;
    rep (i, n) eprintf("%d,", a[i]);
    sort(all(a), [](int a, int b) {return abs(a) < abs(b);});
    rep (i, n) eprintf("%d,", a[i]);
    int ans = 0;
    rep (i, n - 1) ans += a[i + 1];
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3640
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 100001
#define INF (ll)1e18
#define pll pair<ll,ll>
#define pii pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define pi 3.1415926535897

int main() {
    
    get(n);
    vector<pll> A(n);

    rep(i,n) {
        get2(a,b);
        A[i] = {a,b};
    }

    double sum = 0.0;
    std::function<void(ll,ll)> solve = [&](ll l, ll r) {

        if(r==l) {
            rep(i,n-1) {
                double a = (A[i].fi-A[i+1].fi)*(A[i].fi-A[i+1].fi);
                double b = (A[i].se-A[i+1].se)*(A[i].se-A[i+1].se);
                sum += sqrt(a+b);
            }
            return;
        }

        for(ll i=l;i<=r;i++) {
            swap(A[i],A[l]);
            solve(l+1,r);
            swap(A[i],A[l]);
        }
    };

    solve(0,n-1);

    ll f = 1;
    rep2(i,1,n+1)
        f *= i;
    printf("%.10f\n", sum/f);

    return 0;  
}

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

using namespace std;

typedef long long ll;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  char c; cin >> c;
  if ('A' <= c && c <= 'Z') {
    cout << 'A' << endl;
  }
  else {
    cout << 'a' << endl;
  }

  
  return 0;
}




Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    mp[tmp]++;
  }
  int m;
  cin >> m;
  bool x = true;
  for (int i = 0; i < m; i++) {
    int tmp;
    cin >> tmp;
    auto itr = mp.find(tmp);
    if (itr != mp.end()) {
      itr->second--;
      if (itr->second < 0) {
	x = false;
	break;
      }
    }
    else {
      x = false;
      break;
    }
  }
  dump(x ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 9600
import sys
import collections

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')

N, K = [int(x) for x in input().split()]
nums = [int(x) for x in input().split()]

c = collections.Counter(nums)
d = c.most_common()[::-1]
print(sum([d[i][1] for i in range(len(d) - K)]))

Measured memory_bytes: 39576
List=[1]
for i in range(2,32):
  j=2
  while(i**j<=1000):
    List.append(i**j)
    j+=1
#print(List)
x=int(input())
for i in range(x,0,-1):
  if (List.count(i)>0):
    print(i)
    break

Measured memory_bytes: 2940
#include<cstdio>
#include<queue>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int Maxn=1e5;
const long long Tot=1e15;
typedef long long ll;
struct Edge {
	int v;
	ll m[2];
	Edge(int a,int b,int c) {v=a,m[0]=b,m[1]=c;}
};
vector<Edge> G[Maxn+5];
void AddEdge(int u,int v,int x,int y) {
	G[u].push_back(Edge(v,x,y));
	G[v].push_back(Edge(u,x,y));
}
ll dist[2][Maxn+5];
bool vis[Maxn+5];
void SPFA(int s,int ty) {
	queue<int> q;
	memset(vis,0,sizeof vis);
	memset(dist[ty],0x3f,sizeof dist[ty]);
	
	q.push(s);
	vis[s]=true;dist[ty][s]=0;
	
	while(!q.empty()) {
		int u=q.front();
		q.pop();vis[u]=false;
		
		for(int i=0;i<G[u].size();i++) {
			int v=G[u][i].v,w=G[u][i].m[ty];
			if(dist[ty][v]>dist[ty][u]+w) {
				dist[ty][v]=dist[ty][u]+w;
				if(!vis[v]) {
					vis[v]=true;
					q.push(v);
				}
			}
		}
	}
}
int N,M,S,T;
ll ans[Maxn+5];
int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d %d %d %d",&N,&M,&S,&T);
	for(int i=1;i<=M;i++) {
		int u,v,x,y;
		scanf("%d %d %d %d",&u,&v,&x,&y);
		AddEdge(u,v,x,y);
	}
	SPFA(S,0);
	SPFA(T,1);
	ans[N]=dist[0][N]+dist[1][N];
	for(int i=N-1;i>=1;i--)
		ans[i]=min(ans[i+1],dist[0][i]+dist[1][i]);
	for(int i=1;i<=N;i++)
		printf("%lld\n",Tot-ans[i]);
	return 0;
}

Measured memory_bytes: 13184
<?php
// 重み付きUnion-Find：同じグループに属するかどうかの判定と根からの重みを保持する
class UnionFind {
    private $par; // par[$i]:$iの親 自分が根の場合は自身のindexとなる
    private $rank; // rank[$i]:$iの重み
    private $diff_weight; // diff_weight[$i]:$iの重みの差

    function __construct($n, $sum_unity = 0) {
        for ($i = 0; $i < $n; $i++) {
            $this->par[$i] = $i; // 最初は全てが根
            $this->rank[$i] = 0; // 最初は全て0
            $this->diff_weight[$i] = $sum_unity;
        }
    }

    function root($x) { // 根を返す
        if ($this->par[$x] === $x) return $x; // 根の場合
        $r = $this->root($this->par[$x]);
        $this->diff_weight[$x] += $this->diff_weight[$this->par[$x]]; // 全ての枝の重みの差を根との重みの差にする
        return $this->par[$x] = $r; // 全ての枝の親を根にする
    }

     function weight($x) {
         $this->root($x);
         return $this->diff_weight[$x];
     }

    function unite($x, $y, $w) { // $xと$yの木を併合
        $w += $this->weight($x);
        $w -= $this->weight($y);
        $ix = $this->root($x);
        $iy = $this->root($y);
        if ($ix === $iy) return;
        if ($this->rank[$ix] < $this->rank[$iy]) {
            list($ix, $iy) = [$iy, $ix];
            $w = -$w;
        }
        if ($this->rank[$ix] === $this->rank[$iy]) $this->rank[$ix]++;
        $this->par[$iy] = $ix; // $yの根を$xの根に付ける
        $this->diff_weight[$iy] = $w;
    }

    function isSame($x, $y) { // $xと$yの根が同じか
        return $this->root($x) === $this->root($y);
    }

    function diff($x, $y) {
        return $this->weight($y) - $this->weight($x);
    }
}

fscanf(STDIN, '%d %d', $n, $m);

$tree = new UnionFind($n);

for ($i  = 0; $i < $m; $i++) {
    fscanf(STDIN, '%d %d %d', $l, $r, $d);
    $l--; $r--; // 0 ~ $n-1に合わせる
    if ($tree->isSame($l, $r)) {
        $diff = $tree->diff($l, $r);
        if ($diff !== $d) {
            echo 'No'.PHP_EOL;
            exit();
        }
    } else {
        $tree->unite($l, $r, $d);
    }
}
echo 'Yes'.PHP_EOL;

Measured memory_bytes: 19060
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    if(b <= a)cout << "delicious" << endl;
    else{
        if(b-a <= x)cout << "safe" << endl;
        else cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll a,b,k; cin >> a >> b >> k;
  if(2*k>=b-a+2){
    FOR(i, a, b+1) cout << i << endl;
    return 0;
  }
  FOR(i, a, a+k){
    cout << i << endl;
  }
  FOR(i, b-k+1, b+1){
    cout << i << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (b);)
#define trav(x,v) for(auto &x : (v))
#define all(v) (v).begin(),(v).end()
#define sz(v) (int)(v).size()
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;

ll mc[3], mf[] = {2,3,5}, d;

map<ll, ld> mem;

ld rek(ll n){
	if(!mem.count(n)){
		ld ans = ld(n) * d;
		rep(i,0,3){
			int r = n % mf[i];
			ans = min(ans, rek(n/mf[i]) + mc[i] + r * d);
			if(r && n > 1) ans = min(ans, rek(1+n/mf[i]) + mc[i] + (mf[i]-r) * d);
		}
		mem[n] = ans;
	}
	return mem[n];
}

void solve(){
	mem.clear();
	mem[0] = 0;
	ll n;
	cin >> n >> mc[0] >> mc[1] >> mc[2] >> d;
	cout << ll(rek(n)) << endl;
}

int main(){
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);

	int n;
	cin >> n;



	rep(_,0,n) solve();
}


Measured memory_bytes: 4652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int []arr=new int[n];
		for(int i=0;i<n;i++) {
			arr[i]=scn.nextInt();
		}
		int cnt=1;
		int max=arr[0];
		for(int i=1;i<n;i++) {
			if(arr[i]>=max)
				cnt++;
			if(max<arr[i]) {
				max=arr[i];
			}
		}
		System.out.println(cnt);
	}

}


Measured memory_bytes: 23764
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    LL A,B,N;
    R(A,B,N);
    LL x=N;
    if(N>=B)x=B-1;
    W(A*x/B-A*(x/B));
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i, n) for(ll i = 0; i < n; i++)
#define FORR(i, n) for(ll i = n; i >= 0; i--)
#define FORS(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) accumulate(v.begin(),v.end(),0)
#define SORT(v) sort(v.begin(),v.end())
#define OUT(n) (cout << n << endl)
#define IN1(a) (cin >> a)
#define IN2(a,b) (cin >> a >> b)
#define IN3(a,b,c) (cin >> a >> b >> c)
#define IN4(a,b,c,d) (cin >> a >> b >> c >> d)
#define REV(n) reverse(n.begin(), n.end())
using namespace std;
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    string n,ans;
    cin >> n;
    REV(n);
    ans = (n.at(0));
    if ((ans == "2") || (ans == "4") || (ans == "5") || (ans == "7") || (ans == "9")){
        OUT("hon");    
    }
    else if ((ans == "0") || (ans == "1") || (ans == "6") || (ans == "8")){
        OUT("pon");
    }
    else
    {
        OUT("bon");
    }
    
}

Measured memory_bytes: 3572
N = int(input())
a = [int(x) for x in input().split()]
amin, amax = min(a), max(a)

temp = [ai - amin for ai in a]
ans = sum([ai**2 for ai in temp])

for A in range(amin,amax+1):
    for i in range(N):  temp[i] -= 1
    nans = sum([ai**2 for ai in temp])
    if ans > nans:  ans = nans

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
int N; cin>>N;
cout << (N-2)*180 << endl;
}

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second

int main()
{
    string s;
    cin >> s;
    if (s=="ABC") cout << "ARC\n";
    else cout << "ABC\n";


    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    if(x >= 30){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3664
#include <stdio.h>
 int main(void){
  char s[3]={"abc"};
  char d[3]={0};
  int j;
  int count=0,count1=0,count2=0;
  scanf("%s",d);
   for(j=0;j<3;j++){
      if(d[j]=='a')
       count++;
      if(d[j]=='b')
       count1++;
      if(d[j]=='c')
       count2++;
   }
  if(count==1&&count1==1&&count2==1)
  printf("Yes");
  else
  printf("No");
   return 0;
 }


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
vector<int> arr[N];
bool vis[N];
void dfs(int i){
    if(vis[i])
    return ;
    vis[i] = 1;
    for(auto c : arr[i])
        dfs(c);
}
int main() {
    int n , m;
    cin >> n >> m;
    for(int i = 0 ; i < m ; i++){
        int a , b;
        cin >> a >> b;
        arr[a].push_back(b);
        arr[b].push_back(a);
    }
    int ans = -1;
    for(int i = 1 ; i <= n ; i++){
        if(!vis[i])
            ++ans , dfs(i);
    }
    cout<<ans;
}


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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		String[] strArray = br.readLine().split(" ");
		int[] array = new int[n];
		for(int i = 0; i < n; i++){
			array[i] = Integer.parseInt(strArray[i]);
		}

		//int count = bubbleSor(array, n);
		int count = selectionSort(array, n);

		printArray(array);
		System.out.println(count);

	}

	static int bubbleSor(int[] array, int n){
		int flag = 1;
		int count = 0;
		while(flag == 1){
			flag = 0;
			for(int j = n - 1; j >= 1; j--){
				if(array[j] < array[j - 1]){
					int tmp = array[j];
					array[j]  = array[j - 1];
					array[j - 1] = tmp;
					flag = 1;
					count++;
				}
			}
		}

		return count;
	}

	static int selectionSort(int [] array, int n){
		int count = 0;
		for(int i = 0; i < n; i++){
			int minJ = i;
			for(int j = i; j < n; j++){
				if(array[j] < array[minJ]){
					minJ = j;
				}
			}
			int tmp = array[i];
			array[i]  = array[minJ];
			array[minJ] = tmp;
			if(i != minJ){
				count++;
			}
		}

		return count;
	}

	static void printArray(int[] array){
		for(int i = 0; i < array.length ;i++){
			System.out.print(array[i]);
			if(i != array.length - 1){
				System.out.print(" ");
			}
		}
		System.out.println();
	}

}

Measured memory_bytes: 24436
# https://atcoder.jp/contests/abc134/tasks/abc134_b

N, D = map(int, input().split())

count = 0
ans = 1
for i in range(N):
    count += 1

    if count == D*2 + 2:
        ans += 1
        count = 1

print(ans)


#  123 4 567 890 1 234 5
#  ### # ### ### # ### #

Measured memory_bytes: 2940
A, B = (int(s) for s in input().rstrip().split())

if ((B - 2 * A) >= 2 or (4 * A - B) >= 2) and (B - 2 * A) >= 0 and (4 * A - B) >= 0 and (B - 2 * A) % 2 == 0 and (4 * A - B) % 2 == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9188
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
int main() {
	int n,mn=1e9,res=0;cin>>n;
	vi v(n);
	loop(n,i,0)cin>>v[i];
	loop(n,i,0){
		if(mn>=v[i]){
			res++;
			mn=v[i];
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 1024
N = ((4,2,1,3),(0,2,5,3),(4,5,1,0),(4,0,1,5),(5,2,0,3),(4,3,1,2))
while True:
    n = input()
    if n == 0:
        break
    s = set()
    for _ in xrange(n):
        L = raw_input().split()
        M = [L[i] for i in N[L.index("Red")]]
        if "Blue" in M:
            i = M.index("Blue")
        else:
            i = M.index("Cyan")
        s.add(tuple(M[i:] + M[:i]))
    print n - len(s)

Measured memory_bytes: 4240
/*
	拡張ダイクストラ法(ABC164E)
									*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll INF = 1L<<60;
struct edge {
	ll to;
	ll cost;
    ll time;
};
typedef vector<vector<edge>> Graph;
const ll MAXS = 2999;

ll V, E;

vector<vector<ll>> dijkstra(ll f, ll n, ll s, Graph& G){
    s = min(s, MAXS);
    vector<vector<ll>> confirm(n, vector<ll>(MAXS+1, false));
    vector<vector<ll>> mincost(n, vector<ll>(MAXS+1, INF)); mincost[f][s] = 0;
    priority_queue<vector<ll>, vector<vector<ll>>, greater<vector<ll>>> mincand;
    mincand.push({mincost[f][s], f, s});

    while(!mincand.empty()){
        vector<ll> next = mincand.top(); mincand.pop();
        if(confirm[next[1]][next[2]]) continue;
        confirm[next[1]][next[2]] = true;
        vector<edge>& v = G[next[1]]; ll l = v.size();
        for(ll i = 0; i < l; i++){
            ll nextS = min(next[2] + v[i].cost, MAXS);
            if(nextS < 0) continue;
            if(mincost[v[i].to][nextS] <= next[0] + v[i].time) continue;
            mincost[v[i].to][nextS] = next[0] + v[i].time;
            mincand.push({mincost[v[i].to][nextS], v[i].to, nextS});
        }
    }
    return mincost;
}

int solve() {
    ll n, m, s;
    cin >> n >> m >> s;
    vector<ll> u, v, a, b, c, d;
    u.resize(m);
    v.resize(m);
    a.resize(m);
    b.resize(m);
    c.resize(n);
    d.resize(n);
    Graph G(n);
    for(ll i = 0; i < m; i++){
        cin >> u[i] >> v[i] >> a[i] >> b[i];
        edge e = {v[i]-1, -a[i], b[i]};
        G[u[i]-1].push_back(e);
        edge e2 = {u[i]-1, -a[i], b[i]};
        G[v[i]-1].push_back(e2);
    }
    for(ll i = 0; i< n; i++){
        cin >> c[i] >> d[i];
        edge e = {i, c[i], d[i]};
        G[i].push_back(e);
    }
    vector<vector<ll>> mincost = dijkstra(0, n, s, G);
    for(ll i = 1; i < n; i++) cout << *min_element(mincost[i].begin(), mincost[i].end()) << endl;
	return 0;
}

int main() {
	std::cout << std::fixed << std::setprecision(10);
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	return solve();
}


Measured memory_bytes: 10608
#include<iostream>
using namespace std;
main()
{
	int w,h,n;cin>>w>>h>>n;
	int w0=0,h0=0,x,y,a;
	for(int i=0;i<n;i++)
	{
		cin>>x>>y>>a;
		if(a==1)
		{
			w0=max(w0,x);
		}
		else if(a==2)
		{
			w=min(w,x);
		}
		else if(a==3)
		{
			h0=max(h0,y);
		}
		else h=min(h,y);
	}
	if(h0>=h||w0>=w)cout<<0<<endl;
	else cout<<(h-h0)*(w-w0)<<endl;
}


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

int main(void){
    string s,ans="";
    cin>>s;
    reverse(s.begin(),s.end());

    int b_count=0;
    for(char c: s){
        if(c=='B'){
            b_count+=1;
        }else{
            if(b_count==0){
                ans += c;
            }else{
                b_count --;
            }
        }
    }
    reverse(ans.begin(),ans.end());
    
    cout<<ans<<endl;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

const int INF=123456789;

int h,w;
string f[1000];

int dx[8]={0,1,1,1,0,-1,-1,-1}, dy[8]={1,1,0,-1,-1,-1,0,1};
int dp[1000][1000];

inline bool in(int y, int x)
{
    return (0<=y&&y<h && 0<=x&&x<w);
}

int main()
{
    cin >>h >>w;
    rep(i,h) cin >>f[i];

    fill(dp[0],dp[1000],INF);
    rep(i,h)rep(j,w) if(f[i][j]=='.') dp[i][j]=0;

    queue<pi> que;

    rep(i,h)rep(j,w)
    {
        if(dp[i][j]==0)
        {
            rep(k,8)
            {
                int nx=j+dx[k], ny=i+dy[k];
                if(in(ny,nx) && f[ny][nx]!='.')
                {
                    int ct=0;
                    int lim=f[ny][nx]-'0';
                    rep(l,8)
                    {
                        int nnx=nx+dx[l], nny=ny+dy[l];
                        if(f[nny][nnx]=='.') ++ct;
                    }

                    if(ct>=lim)
                    {
                        dp[ny][nx]=1;
                        que.push(pi(ny,nx));
                    }
                }
            }
        }
    }

    while(!que.empty())
    {
        pi now=que.front();
        que.pop();
        rep(i,8)
        {
            int nx=now.se+dx[i], ny=now.fi+dy[i];

            if(f[ny][nx]=='.') continue;
            if(f[ny][nx]=='9') continue;

            vector<int> a;
            rep(j,8)
            {
                int nnx=nx+dx[j], nny=ny+dy[j];
                a.pb(dp[nny][nnx]);
            }
            sort(all(a));

            int p=f[ny][nx]-'0';

            if(dp[ny][nx]>a[p-1]+1)
            {
                dp[ny][nx]=a[p-1]+1;
                que.push(pi(ny,nx));
            }
        }
    }

    int ans=0;
    rep(i,h)rep(j,w) if(dp[i][j]!=INF) ans=max(ans,dp[i][j]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8016
import java.util.Scanner;
import java.lang.String;

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


        int n = sc.nextInt();
        int k = sc.nextInt();

        String s = sc.next();

        StringBuilder str = new StringBuilder();

        for (int i = 0; i < n; i++) {
            String si = s.substring(i,i+1);
            if(i+1 == k){
                str.append(si.toLowerCase());
            }else{
                str.append(si);
            }
        }

        System.out.println(str.toString());

        sc.close();
    }
}


Measured memory_bytes: 21844