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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF ((1LL<<62)-1)
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME ((1ll<<61)-1)

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

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

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

bool isout(int h, int w, int H, int W) {
	return ( h<0 || h>=H || w<0 || w>=W );
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int N;
ll ans;
llvec A,rui;

void input() {
	cin>>N;
	init(A,N);
	rui.resize(N+1,0);
}

void solve() {
	for(int i=0; i<N; i++) {
		rui[i+1] = (rui[i]+A[i])%MPRIME;
	}

	for(int i=1; i<N; i++) {
		ans = (ans + rui[i]*A[i])%MPRIME;
	}
	cout<<ans<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 6360
cards = [[True for i in range(13)] for j in range(4)]

n = int(input())
for i in range(n):
    mark, number = input().split()
    number = int(number)
    
    if mark == 'S':
        cards[0][number-1] = False
    elif mark == 'H':
        cards[1][number-1] = False
    elif mark == 'C':
        cards[2][number-1] = False
    else:
        cards[3][number-1] = False
        
for i in range(4):
    for j in range(13):
        if cards[i][j] == True:
            if i == 0:
                print("S ", j+1, sep="")
            elif i == 1:
                print("H ", j+1, sep="")
            elif i == 2:
                print("C ", j+1, sep="")
            else:
                print("D ", j+1, sep="")


Measured memory_bytes: 5608
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <string>
#include <cmath>
#include <algorithm>
#define CHAR_NUM 1025
using namespace std;

int isexcept(int ch);
void reverse(char str[]);

int main(void) {
    string str;
    char ans[CHAR_NUM] = {'\0'};
    int i, j, len;
    int count = 0;
    
    getline(cin, str);
    
    for(i = 0; str[i]; i++) {
        char temp[10] = {'\0'};
        int idx = 0;
        if(isexcept(str[i])) {
            count++;
        } else if(count > 2 && count < 7) {
            count = 0;
            for(j = i - 1; (isexcept(str[j]) && !(j < 0)); j--) {
                temp[idx++] = str[j];
            }
            reverse(temp);
            strcat(ans, temp);
            len = (int)strlen(ans);
            ans[len] = ' ';
        } else {
            count = 0;
        }
    }
    len = (int)strlen(ans);
    ans[len - 1] = '\0';
    
    cout << ans << endl;
    
    return(0);
}
 
int isexcept(int ch) {
    return((ch != ',' && ch != ' ') && ch != '.');
}

void reverse(char str[]) {
    char temp[2] = {'\0'};
    int i;
    int len = (int)strlen(str);
    
    for(i = 0; i < len / 2; i++) {
        temp[0] = str[len - 1 - i];
        str[len - 1 - i] = str[i];
        str[i] = temp[0];
    }
}

Measured memory_bytes: 1180
#include <iostream>
#include <string>
#include <algorithm>

int count(const std::string& s, char ch) {
  int num = 0;
  int len = s.length();
  char cur, pre = 'a';
  for (int i = 0; i < len; ++i) {
    char cur = s[i] == '?' ? ch : s[i];
    if (cur == 'D') {
      ++num;
      if (pre == 'P') ++num;
    }
    pre = cur;
  }
  return num;
}

void solve(std::string* s) {
  int p_num = count(*s, 'P');
  int d_num = count(*s, 'D');
  char ch = p_num >= d_num ? 'P' : 'D';
  int len = s->length();
  for (int i= 0; i < len; ++i) {
    if (s->at(i) == '?') 
      s->at(i) = ch;
  }
}

int main() {
  std::string s;
  std::cin >> s;
  solve(&s);
  std::cout << s << std::endl;
  return 0;
}


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

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

int main() {

    int r, g, b; cin >> r >> g >> b;

    int t = 100 * r + 10 * g + b;

    if (t % 4 == 0) {
        puts("YES");
    } else {
        puts("NO");
    }
}

Measured memory_bytes: 256
#include<iostream>
#include <map>
using namespace std;
int main()
{
int n;
cin>>n;
map<string,int>freq;
for(int i=0; i<n; ++i)
{
string s;
cin>>s;
++freq[s];
}
cout<<"AC x"<<" "<<freq["AC"]<<"\n";
cout<<"WA x"<<" "<<freq["WA"]<<"\n";
cout<<"TLE x"<<" "<<freq["TLE"]<<"\n";
cout<<"RE x"<<" "<<freq["RE"];
}


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

using namespace std;

#define fast_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define int long long
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define MOD 1000000007

const int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};

int n, m, i;

signed main()
{
    fast_IO;
    int test = 1;
    // cin >> test;
    while(test--)
    {
        long double x;
        cin >> n >> x;
        int cnt = 0;
        for(i = 0; i < n; i++)
        {
            long double a, b;
            cin >> a >> b;
            if(x >= sqrt(a*a + b*b))
                cnt++;
        }
        cout << cnt;
    }
    return 0;
} 

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, m, k, ans;
string s;

int main() {
    cin >> s;
    n = s.length();
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') {
            s[i] = '9';
        } else if (s[i] == '9') {
            s[i] = '1';
        }
    }
    cout << s << endl;
    return 0;
}


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

using namespace std;

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

int main()
{
    int x;
    int n;
    int rcounter;
    int lcounter;
    rcounter = 0;
    lcounter = 0;

    cin >> x >> n;
    vector<int> v(n);

    rep(it, 0, n)
        cin >> v[it];

    if (n==0) {
        cout << x << "\n";
        return 0;
    }

    while (true) {
        if (find(v.begin(), v.end(), x+rcounter) != v.end()) {
            // in right
            rcounter++;
            if (find(v.begin(), v.end(), x-lcounter) != v.end()) {
                // in left
                lcounter++;
                continue;
            } else {
                cout << x-lcounter << "\n";
                return 0;
            }
        } else {
            // not in right
            if (find(v.begin(), v.end(), x-lcounter) != v.end()) {
                // in left
                cout << x+rcounter << "\n";
                return 0;
            } else {
                // not in left
                cout << x-lcounter << "\n";
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3584
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdio.h>

using namespace std;

int main(void)
{
    int a,b;cin>>a>>b;
    int ans=1;
    if(b==1){cout<<0<<endl;return 0;}
    for(int i=a;i<b;i+=(a-1))ans++;
    cout<<ans;
    return 0;
}



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

int main() {
    string S;
    cin >> S;
    bool judge = true;
    if (S[0] != 'A') judge = false;
    int count = 0, p = 0;
    for (int i = 2; i < S.size() - 1; i++) {
        if (S[i] == 'C') {
            count++;
            p = i;
        }
    }
    if (count != 1) judge = false;
    for (int i = 1; i < S.size(); i++) {
        if (i == p) continue;
        if (S[i] < 'a' || 'z' < S[i]) judge = false;
    }
    cout << (judge ? "AC" : "WA") << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().strip().split())
result = 0
num = N // K
result += num
if num == 2:
    result += num * (num - 1) * 3
elif num > 2:
    result += num * (num - 1) * 3
    result += num * (num - 1) * (num - 2)


if K % 2 == 1:
    print(result)
else:
    start = K // 2
    num = (N - start) // K + 1
    result += num
    if num == 2:
        result += num * (num - 1) * 3
    elif num > 2:
        result += num * (num - 1) * 3
        result += num * (num - 1) * (num - 2)
    print(result)

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] sum = new long[n+1];
		sum[1] = 1;
		for (int i = 2; i < n+1; i++) {
			if (i % 3== 0 || i%5 ==0) {
				sum[i] = sum[i-1];
			} else {
				sum[i] = sum[i-1] + i;
			}
		}
		System.out.println(sum[n]);
	}

}


Measured memory_bytes: 43504
X = int(input())
tane = [x**5 for x in range(130)]

flag = 0
for i in range(len(tane)):
    for j in range(len(tane)):
        a = tane[i]
        b = tane[j]
        if a - b == X:
            print(i,j)
            flag = 1
            break
        elif -a -b ==X:
            print(-i,j)
            flag = 1
            break
        elif a + b == X:
            print(i,-j)
            flag = 1
            break
        elif -a + b == X:
            print(-i,-j)
            flag = 1
            break
    if flag == 1:
        break

Measured memory_bytes: 65504
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

void add(int& x, int y) {
  x = (x + y) % MOD;
}

const int N = 300 + 10;
vector<ii> a[N];
int dp[N][N][N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int L, R, cnt;
    scanf("%d%d%d", &L, &R, &cnt);
    a[R].push_back({L, cnt});
  }
  dp[0][0][0] = 1;
  int ret = 0;
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      if (i && i == j) continue;
      for (int k = 0; k <= n; ++k) {
        if (k && (k == i || k == j)) continue;
        vector<int> A = {i, j, k};
        sort(A.begin(), A.end());
        int len = A[2];
        bool valid = true;
        for (auto& it : a[len]) {
          int L = it.first, cnt = it.second;
          if ((L <= A[0] && cnt != 3) ||
              (L > A[0] && L <= A[1] && cnt != 2) ||
              (L > A[1] && cnt != 1)) {
            valid = false;
            break;
          }
        }
        if (!valid) dp[i][j][k] = 0;
        // trace(i, j, k, len == n, valid, dp[i][j][k]);
        if (len == n) add(ret, dp[i][j][k]);
        add(dp[len + 1][j][k], dp[i][j][k]);
        add(dp[i][len + 1][k], dp[i][j][k]);
        add(dp[i][j][len + 1], dp[i][j][k]);
      }
    }
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 114944
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    vector<vector<ll>> ans(2, vector<ll>(n));
    int l = 0;
    rep(i, n){
        while(b[i] >= c[l] && l < n){
            l++;
        }
        ans[1][i] = n - l;
    }
    for(int i = n - 1; i > 0; --i){
        ans[1][i - 1] += ans[1][i];
    }
    l = 0;
    rep(i, n){
        while(a[i] >= b[l] && l < n){
            l++;
        }
        if(l < n){
            ans[0][i] = ans[1][l];
        }else{
            ans[0][i] = 0;
        }
    }
    ll sum = 0;
    rep(i, n) sum += ans[0][i];
    cout << sum << endl;
}

Measured memory_bytes: 3712
exec("def nWord(): nWord.cache = raw_input() if not hasattr(nWord, 'cache') or nWord.cache=='' else nWord.cache ; pos = nWord.cache.find(nWord.sep) ; ret, nWord.cache = (nWord.cache, '') if pos==-1 else (nWord.cache[:pos], nWord.cache[pos+1:].lstrip(nWord.sep)) ; return ret") ; exec("nWord.sep = ' '") ; exec("def ___nLine2(): ret, nWord.cache = (raw_input(), nWord.cache if hasattr(nWord, 'cache') else '') if not hasattr(nWord, 'cache') or nWord.cache=='' else (nWord.cache, '') ; return ret") ; exec('def nInt(): return int(nWord())') ; exec('def nFloat(): return float(nWord())') ; exec("def ___nAuto2():\n ret = nWord()\n try: return int(ret)\n except: pass\n try: return float(ret)\n except: return ret") ; exec("def nAuto(n=None): return ___nAuto2() if n is None else [___nAuto2() for i in range(n)]") ; exec("def nLine(n=None): return ___nLine2() if n is None else [___nLine2() for i in range(n)]")
 
N = nAuto()
S = nAuto(N)
 
def check(A):
    for i in range(N):
        for j in range(N):
            if S[(A+i) % N][j]!=S[(A+j) % N][i]:
                return 0
    return N
 
count = 0
for A in range(N):
    count += check(A)
print count

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

vector< vector<int> > graph;
bool visited[200001] = {false};
int NOWLEN;

void dfs(int now) {
    if (visited[now]) return;
    visited[now] = true;
    NOWLEN++;
    for (auto it=graph[now].begin(); it<graph[now].end(); it++) {
        if (!visited[*it]) {
            dfs(*it);
        }
    }
}

int main() {
    int N, M; cin>>N>>M;
    graph.resize(N+1);
    for (int i=0; i<M; i++) {
        int A, B; cin>>A>>B;
        graph[A].push_back(B);
        graph[B].push_back(A);
    }
    int mx = 0;
    for (int i=1; i<=N; i++) {
        if (!visited[i]) {
            NOWLEN = 0;
            dfs(i);
            mx = max(NOWLEN, mx);
        }
    }
    cout<<mx;
}

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

using namespace std;

long long int N, maxa, maxt, sameai = -1, sameti = -1, ans = 1, sames;
long long int T[100000], A[100000];
long long int mod = (long long int)(1e9+7);

void modpow(long long int p, long long int i){
    if(i < 0){
        i = -i;
    }
    while(i != 0){
        if(i % 2 == 0){
            p = (p * p) % mod;
        }else{
            ans = (ans * p) % mod;
            p = (p * p) % mod;
        }
        i /= 2;
    }
}

int main(){
    ans = 1;
    scanf("%lld", &N);
    for(int i = 0; i < N; i++){
        scanf("%lld", T + i);
    }
    for(int i = 0; i < N; i++){
        scanf("%lld", A + i);
    }
    maxa = A[0];
    maxt = T[N - 1];
    //cout << "maxa = " << maxa << ", maxt = " << maxt << endl;
    //cout << "A check" << endl;
    for(int i = 0; i < N; i++){
        if(T[i] == maxa){
            if(A[i] != maxa){
                cout << 0 << endl;
                return 0;
            }
            sameai = i;
            break;
        }
    }
    if(sameai == -1){
        cout << 0 << endl;
        return 0;
    }
    for(int i = N - 1; i >= 0; i--){
        if(A[i] == maxt){
            if(T[i] != maxt){
                cout << 0 << endl;
                return 0;
            }
            sameti = i;
            break;
        }
    }
    if(sameti == -1){
        cout << 0 << endl;
        return 0;
    }
    //cout << sameti << ", " << sameai << endl;
    //cout << ans << endl;
    for(int i = 1; i < sameai + 1; i++){
        //cout << i << " : " << ans << ", " << sames << endl;
        if(T[i - 1] == T[i]){
            sames++;
        }else{
            modpow(T[i - 1], sames);
            sames = 0;
        }
    }
    modpow(T[sameti], max((long long int)0, sameti - sameai - 1));
    for(int i = sameti; i < N; i++){
        //cout << i << " : " << ans << ", " << sames << endl;
        if(A[i + 1] == A[i]){
            sames++;
        }else{
            modpow(A[i], sames);
            sames = 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr ll inf = 1ll<<60;
int main(){
    int n,ma,mb;
    cin>>n>>ma>>mb;
    vector<vector<vector<int>>> dp(n+1,vector<vector<int>>(405,vector<int>(405,1<<25)));
    dp[0][0][0] = 0;
    for(int i=0;i<n;++i){
        int cura,curb,curc;
        cin>>cura>>curb>>curc;
        for(int a=0;a<=400;++a)for(int b=0;b<=400;++b){
            dp[i+1][a][b] = dp[i][a][b];
            if(a - cura >= 0 && b - curb >= 0){
                dp[i+1][a][b] = min(dp[i+1][a][b],dp[i][a - cura][b - curb] + curc);
            }
        }
    }
    
    int ret = 1<<25;
    for(int a=1;a<=400;a++){
        for(int b=1;b<=400;b++){
           if(a*mb == b*ma){
               ret = min(ret,dp[n][a][b]);
           }
        }
    }
    if(ret == 1<<25) cout << -1 << endl;
    else cout << ret << endl;
    return 0;
}



Measured memory_bytes: 27776
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  ll ta, tb; ll aa, ab; ll ba, bb;
  cin >> ta >> tb >> aa >> ab >> ba >> bb;
  if(ta*aa+tb*ab==ta*ba+tb*bb) cout << "infinity" << endl;
  else{
    if(aa<ba){
      swap(aa, ba); swap(ab, bb);
    }
    if(ta*aa+tb*ab-ta*ba-tb*bb>0){
      cout << 0 << endl; return 0;
    }
    ll tmp=ta*(aa-ba)/(ta*ba+tb*bb-ta*aa-tb*ab);
    if((ta*(aa-ba))%(ta*ba+tb*bb-ta*aa-tb*ab)==0){
      cout << 2*tmp << endl;
    }
    else{
      cout << tmp*2+1 << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long unsigned int ll;
using namespace std;
const ll size = 1000000;// 1e6 + 1
// int dp[size][size];
// ll calc(ll a, ll b){
//   // cout << MOD << endl;
//   if(a == 1&&b > 2){return 0;}
//   if(b == 1&&a > 2){return 0;}
//   if(a == 0){return 0;}
//   if(b == 0){return 0;}
//   if(a == 1&&b==2){return 1;}
//   if(a == 2&&b==1){return 1;}
//   else{return (calc(a - 1,b - 2) + calc(a - 2,b - 1))%MOD;}

// }
vector<ll> fac(2*size); //n!(mod M)
vector<ll> ifac(2*size); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

int main()
{
  ll x, y;
  cin >> x >> y;

  fac[0] = 1;
  ifac[0] = 1;
  for(ll i = 0; i<2*size; i++){
    fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
    ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD; // k!^{M-2} (mod M) ←累乗にmpowを採用
  }
  if(x == 1){
    if(y == 2){
      cout << 1 << endl;
      return 0;
    }else{cout << 0 << endl; return 0;}
  }
  if(x == 2){
    if(y == 1){
      cout << 1 << endl;
      return 0;
    }else{cout << 0 << endl; return 0;}
  }
  if((x + y)%3 != 0){
    cout << 0 << endl;
    return 0;
  }
  if((-x + 2*y)%3 != 0){
    cout << 0 << endl;
    return 0;
  }
  if((2*x - y)%3 != 0){
    cout << 0 << endl;
    return 0;
  }
  ll a = (-x + 2*y)/3;
  ll b = (2*x - y)/3;
  ll c = min(a, b);
  ll ans = comb(a + b,c)%MOD;
  cout << ans<< endl;
}


Measured memory_bytes: 31488
#include<stdio.h>
int main()
{
    int n,rev=0,rem,a;
    scanf("%d",&n);
    a=n;
    while(n!=0 )
    {
        rem = n%10;
        rev = rev*10 + rem;
        n /= 10;
    }

    if (a == rev)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 128
n = int(input())
h = [int(i) for i in input().split()]
INF = float("INF")
dp = [INF]*n
dp[0] = 0
dp[1] = abs(h[0]-h[1])
for i in range(2,n):
    dp[i] = min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]))
print(dp[n-1])

Measured memory_bytes: 13928
#include<iostream>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    int k = (N-1)*(N-2) / 2;
    if(k < K) {
        cout << -1 << endl;
    } else {
        cout << k - K + N - 1 << endl;
        for(int i = 2; i <= N; i++) cout << 1 << " " << i << endl;
        if(k == K) return 0;
        
        for(int i = 2; i <= N; i++){
            for(int j = i+1; j <= N; j++){
                cout << i << " " << j << endl;
                k--;
                if(k == K) return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char** argv){
    int A, B, ans;
    cin >> A >> B;
    ans = -1;

    if (25*A >= 20*B+20 || 20*B >= 25*A+25){
        ans = -1;
    } else{
        int Xmin, Xmax;
        if (A%2 == 0){
            Xmin = 25*A/2;
            Xmax = 25*A/2 + 12;
        } else {
            Xmin = (25*A+1)/2;
            Xmax = 25*(A+1)/2 - 1;
        }
        for (int X=Xmin; X<=Xmax; X++){
            if (10*B <= X && X < 10*(B+1)){
                ans = X;
                break;
            }
        }
    }
    cout << ans << "\n";

    return 0;
}


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

using namespace std;

// Problem https://atcoder.jp/contests/abc075/tasks/abc075_b
// Reference https://atcoder.jp/contests/abc075/submissions/1682902

vector<vector<int>> solver(int height,int width,vector<string> gridMap)
{
    vector<vector<int>> result(height,vector<int>(width,0));
    // x軸y軸の操作関連の配列(vector)。上から時計回りで8方向
    vector<int> dx={0,1,1,1,0,-1,-1,-1};
    vector<int> dy={1,1,0,-1,-1,-1,0,1};
    
    for(int j=0;j<height;j++){
        for(int k=0;k<width;k++){
                if(gridMap.at(j).at(k)=='#'){// そもそも爆弾ならば結果に-1をセット
                    result.at(j).at(k)=-1;
                }
                else{
                    for(int d=0;d<8;d++){// それ以外[.]なら方向別操作
                    int nowH=j+dy.at(d);
                    int nowW=k+dx.at(d);
                    if(nowH < 0 || height <= nowH || nowW < 0 || width <= nowW){
                        continue; // 今回のループは脱出
                    }
                    else{
                        if(gridMap.at(nowH).at(nowW) == '#'){
                            result.at(j).at(k)=result.at(j).at(k)+1;
                        }
                    }
                }
            }
        }

    }

    return result;
}

int main(void){
    
    int H,W;
    cin >> H >> W ;
    vector<string> gridMap;
    for(int j=0;j<H;j++)
    {
        string lineStr;
        cin >> lineStr;
        gridMap.push_back(lineStr);
    }

    vector<vector<int>> answer(H,vector<int>(W,0));
    answer = solver(H,W,gridMap);
    for(int j=0;j<H;j++)
        {
            for(int k=0;k<W;k++){
                if(answer.at(j).at(k)==-1)
                {
                    cout << '#';
                }
                else{
                cout << answer.at(j).at(k);
                }
            }
            cout << endl;
        }
    return 0;
}

Measured memory_bytes: 256
function Main(input) {

    var tmp = input.split('');
    var total = 0;
    for(i = 0 ; i < tmp.length; i++) {
        if (tmp[i] === '1') {
            total = total + 1;
        }
    }
    console.log(total);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <stdio.h>

void InputData(int array[][100], int c, int r) {
	
	int i, j;

	for (i = 0; i < c; i++) {
		int temp = 0;
		for (j = 0; j < r; j++) {
			scanf("%d", &array[i][j]);
		}
	}	
}

void OutputData(int array[][100], int c, int r) {
	int i, j;
	int temp = 0, ans = 0;

	for (i = 0; i < c; i++) {
		for (j = 0; j < r; j++) {
			printf("%d ", array[i][j]);
			temp += array[i][j];
		}
		printf("%d\n", temp);
		temp = 0;
	}

	for (i = 0; i < r; i++) {
		for (j = 0; j < c; j++) {
			temp += array[j][i];
		}
		printf("%d ", temp);
		ans += temp;
		temp = 0;
	}

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

int main(void)
{
	int c, r;
	int array[100][100] = { 0 };

	scanf("%d %d", &c, &r);

	InputData(array, c, r);
	OutputData(array, c, r);

	return 0;

}

Measured memory_bytes: 648
k = int(input())
arr =  [0]*(k+1)
count = [0]*(k+1)
sum = 0
n = 3
for i in range(k,1,-1):
    x = k//i
    p = int(pow(x,n))
    arr[i]=i*p 
    count[i]=p
    for j in range(x-1):
        arr[i]-=i*count[i*(j+2)]
        count[i]-=count[i*(j+2)]
csum = 0
for i in range(2,k+1):
    sum+=arr[i]
    csum+=count[i]
sum+=(int(pow(k,n)) - csum)
print(int(sum%(1e9+7)))



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

using namespace std;

int main(){

	int N = 0;
	cin >> N;
	long long m = 0, a = 0, r = 0, c = 0, h = 0;

	for (int i = 0; i < N; i++){
		string S;
		cin >> S;

		switch (S[0]){
			case 'M':
				m++;
				break;
			case 'A':
				a++;
				break;
			case 'R':
				r++;
				break;
			case 'C':
				c++;
				break;
			case 'H':
				h++;
				break;
		}
	}
	long long ans = m*a*(r + c + h) + m*r*(c + h) + m*c*h + a*r*(c + h) + a*c*h + r*c*h;
	std::cout << ans << std::endl;

	return 0;
}

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

//vector <long long> v[1000000];

//stack <long long> pus, wyn;

long long int  x[1000000], y, z, czy=0, w, n, m;
char s[10][10];

int main()
{
    long long int a, b, c, d, k, i, j, q, t, p;

//    q=1;


//    scanf("%lld", &q);
//    for(t=0; t<q; t++)
    {
        scanf("%lld%lld%lld", &a, &b, &c);
        for(i=0; i<a; i++)scanf("%s", s[i]);
        x[0]=1;
        for(i=1; i<10; i++)x[i]=x[i-1]*2;

        n=1;
        k=1;

        for(i=0; i<a; i++)n*=2;
        for(i=0; i<b; i++)k*=2;

        w=0;

        for(i=0; i<n; i++)
        {
            for(j=0; j<k; j++)
            {
                d=0;
                for(y=0; y<a; y++)
                {
                    for(z=0; z<b; z++)
                    {
                        if(i&x[y] && j&x[z] && s[y][z]=='#'){d++;}
                    }
                }
                if(d==c)w++;
            }
        }

        printf("%lld\n", w);
    }

    return(0);
}


Measured memory_bytes: 3812
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define N 1050
int n,A,B,C,D;
ll f[N][N],fac[N],inv[N],ii[N];
void upd(ll &x,ll y) {
	x+=y; if(x>=mod) x-=mod;
}
ll qp(ll x,ll y) {
	ll re=1;
	for(;y;y>>=1,x=x*x%mod) if(y&1) re=re*x%mod; return re;
}
int main() {
	scanf("%d%d%d%d%d",&n,&A,&B,&C,&D);
	int i,j,k;
	f[A-1][0]=1;
	for(i=1;i<=n;i++) ii[i]=qp(i,mod-2);
	for(fac[0]=i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
	inv[n]=qp(fac[n],mod-2);
	for(i=n-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	for(i=A-1;i<B;i++) {
		for(j=0;j<=n;j++) if(f[i][j]) {
			upd(f[i+1][j],f[i][j]);
			ll tmp=1;
			for(k=1;k<=D&&j+(i+1)*k<=n;k++) {
				tmp=tmp*fac[n-j-(i+1)*(k-1)]%mod*inv[n-j-(i+1)*k]%mod*inv[i+1]%mod*ii[k]%mod;
				if(k>=C) {
					upd(f[i+1][j+(i+1)*k],f[i][j]*tmp%mod);
				}
			}
		}
	}
	printf("%lld\n",f[B][n]);
}


Measured memory_bytes: 8448
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = myconv(next(),1);
  var list = myconv(next(),4);
  var set = new Set();
  for(var i = 0; i < N; i++){
    if(!set.has(list[i])){
       set.add(list[i]);
    }else{
      myout("NO");
      return;
    }
    
  }
  myout("YES");
}

Measured memory_bytes: 43460
#include<stdio.h>
#define MAX 250

int parent(int i){
  return i / 2;
}

int left(int j){
  return 2 * j;
}

int right(int k){
  return 2 * k + 1;
}

int main(){
  int h,i,A[MAX+1];

  scanf("%d",&h);

  for(i = 1;i <= h;i++){
    scanf("%d",&A[i]);
  }

  for(i = 1;i <= h;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i) >= 1){
      printf("parent key = %d, ",A[parent(i)]);
    }
    if(left(i) <= h){
      printf("left key = %d, ",A[left(i)]);
    }
    if(right(i) <= h){
      printf("right key = %d, ",A[right(i)]);
    }
    printf("\n");
  }

  return 0;
  
}



Measured memory_bytes: 2036
#include <iostream>
using namespace std;
int main(void)
{
	int N, K;
	while(cin >> N >> K){
		if(!N) break;
		int S[100]={0};
		for(int i=0; i<K; i++){
			cin >> S[i];
		}
		bool f=false;
		for(int i=0; i<N; i++){
			int B[100]={0};
			for(int j=0; j<K; j++){
				cin >> B[j];
				S[j] -= B[j];
				if(S[j]<0) {
					f = true;
				}
			}
		}
		if(f) cout << "No\n";
		else cout << "Yes\n";
	}
	return 0;
}

Measured memory_bytes: 844
#include<stdio.h>
int main(){
    int h,n;
    scanf("%d%d",&h,&n);
    int sum=0,a[n+1];
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    if(sum>=h)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 512
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))

ans_i = -1
ans_d = 10**18
for i,h in enumerate(H):
    t = T - h * 0.006
    if abs(t-A) < ans_d:
        ans_d = abs(t-A)
        ans_i = i
print(ans_i + 1)

Measured memory_bytes: 3064
use std::io;


fn main() {
    let (n, k) = {
        let i = read::<usize>();
        (i[0], i[1])
    };

    if k % 2 != 0 {
        println!("{}", (n / k).pow(3));
    } else {
        let mut cnt: usize = 0;
        for i in 0..n + 1 {
            if i % k == k / 2 { cnt += 1; }
        }
        println!("{}", (n / k).pow(3) + cnt.pow(3));
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
N = int(input())
E=[[] for _ in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    E[a-1].append((b-1,i))
    E[b-1].append((a-1,i))

C = [0] * (N-1)
stack=[0]
max_c=0
while stack:
    n=stack.pop()
    u=set()
    for to,i in E[n]:
        if C[i]!=0:
            u.add(C[i])
    c=1
    for to,i in E[n]:
        if C[i]!=0:
            continue
        while c in u:
            c+=1
        C[i]=c
        max_c=max(max_c,c)
        c+=1
        stack.append(to)

print(max_c)
print('\n'.join(map(str,C)))

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

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  string u = t.substr(0, n);
  if (s == u) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	priority_queue<int, vector<int>, greater<int>> pq;
	rep(i, n) {
		int a;
		cin >> a;
		pq.push(a);
	}
	vector<P> p(m);
	rep(i, m) cin >> p[i].second >> p[i].first;
	sort(rall(p));
	rep(i, m) {
		rep(j, p[i].second) {
			if (p[i].first > pq.top()) {
				pq.pop();
				pq.push(p[i].first);
			}
			else {
				break;
			}
		}
	}
	ll ans = 0;
	while (pq.size()) ans += pq.top(), pq.pop();
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1528
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
#define ALL(X) X.begin(), X.end()
using lint = long long;
template <typename T>
void print_container(std::vector<T> vec)
{
    for (auto iter = vec.begin(); iter != vec.end(); ++iter)
    {
        std::cout << *iter << " ";
    }
    std::cout << std::endl;
}

lint popcount(lint n)
{
    lint out = 0;

    for (int i = 0; i < 12; ++i)
    {
        if ((n & 1) == 1)
            out++;
        n >>= 1;
    }

    return out;
}

int main()
{
    lint n;
    scanf("%lld", &n);

    std::vector<lint> f(n);

    for (int i = 0; i < n; ++i)
    {
        lint coef = 1 << 9;
        lint num = 0;
        lint bi;
        for (int j = 0; j < 10; ++j)
        {
            scanf("%lld", &bi);
            num += bi * coef;
            coef >>= 1;
        }
        f[i] = num;
    }

    std::vector<std::vector<lint>> p(n, std::vector<lint>(11, 0));

    for (int i = 0; i < n; ++i)
    {
        lint ben;
        for (int j = 0; j < 11; ++j)
        {
            scanf("%lld", &ben);
            p[i][j] = ben;
        }
    }

    lint bene_max = -10000000000;

    for (lint i = 1; i < (1 << 10); i++)
    {
        lint bene = 0;
        for (int j = 0; j < n; ++j)
        {
            bene += p[j][popcount(i & f[j])];
        }
        bene_max = std::max(bene_max, bene);
    }

    std::cout << bene_max << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

template<class T> inline int sgn(T n) { if (n > 0) return 1; else if (n < 0) return -1; else return 0; }

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 () {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  
  SORT(a);

  rep(i,n) {
    if (n%2 == 0 && a[i] != 1+i/2*2) {
      cout << 0 << endl;
      return 0;
    }
    if (n%2 != 0 && a[i] != (i+1)/2*2) {
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = 1;
  rep(_,n/2) {
    ans *= 2;
    ans %= mod;
  }

  cout << ans << endl;
 }


Measured memory_bytes: 640
package main

import (
	"fmt"
	"math"
)

const (
	BUFSIZE   = 10000000
	MOD       = 1000000007
	INF_INT   = math.MaxInt32
	INF_INT64 = math.MaxInt64
)

// var rdr = bufio.NewReaderSize(os.Stdin, BUFSIZE)

func main() {
	solve()
}

func solve() {
	var N, K, Q int
	fmt.Scanf("%d %d %d", &N, &K, &Q)
	scores := make([]int, N)
	for i := 0; i < Q; i++ {
		var a int
		fmt.Scan(&a)
		scores[a-1] += 1
	}

	for _, v := range scores {
		if K-Q+v > 0 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 6332
if __name__ == '__main__':
    n = int(input())
    a = list(map(int,input().split()))
    asort = sorted(a,reverse=True)
    if n % 2 == 0:
        use = n // 2
        res = sum(asort[:use])*2 - max(asort)
    else:
        use = n // 2 + 1
        res = sum(asort[:use])*2 - max(asort) - min(asort[:use])
    print(res)    

Measured memory_bytes: 105312
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int a,b;
  cin >> a >> b;
  if(a==b) cout << "Yes" << "\n";
  else cout << "No" << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX_N 100000
#define MOD 1000000007

typedef long long lint;

lint fact(int n)
{
    lint fac = 1;
    for (int i = 1; i <= n; i++)
        fac = (fac * i) % MOD;
    return fac;
}

int main(void)
{
    int n, m;
    lint ans;
    scanf("%d%d", &n, &m);
    switch (n - m) {
    case 0: ans = (2 * fact(n) * fact(n)) % MOD; break;
    case 1: case -1: ans = (fact(n) * fact(m)) % MOD; break;
    default: ans = 0;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static int count = 0;
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int length = scanner.nextInt();
		int[] array = new int[length];
		for (int i=0; i<length; i++) {
			array[i] = scanner.nextInt();
		}
		scanner.close();
		
		bubbleSort(array, length);
		printArray(array);
		System.out.println(count);
	}
	
	public static void bubbleSort(int[] array, int length) {
		// Variable i stands for the smallest value at this moment.
		// j to traverse the remain items, identify the position of the smallest value in the remain queue.
		for (int i=0; i<length; i++) {
			int mini = i;
			for (int j=i+1; j<length; j++) {
				if (array[j] < array[mini]) {
					mini = j;
				}
			}
			// Swap mini and i if mini!=i
			if (mini != i) {
				array[mini] = array[mini] + array[i];
				array[i] = array[mini] - array[i];
				array[mini] = array[mini] - array[i];
				count++;
			}
		}
	}
	
	public static void printArray(int[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i>0) System.out.print(" ");
			System.out.print(array[i]);
		}
		System.out.print("\n");
	}
}



Measured memory_bytes: 26464
from collections import defaultdict
from heapq import heappush, heappop

N = int(input())
Vx = [None] * N
Vy = [None] * N
for i in range(N):
    x, y = map(int, input().split())
    Vx[i] = (i, x)
    Vy[i] = (i, y)
Vx.sort(key=lambda v: v[1])
Vy.sort(key=lambda v: v[1])
E = defaultdict(list)
for j in range(N-1):
    E[Vx[j][0]].append((Vx[j+1][1] - Vx[j][1], Vx[j+1][0]))
    E[Vx[j+1][0]].append((Vx[j+1][1] - Vx[j][1], Vx[j][0]))
    E[Vy[j][0]].append((Vy[j + 1][1] - Vy[j][1], Vy[j + 1][0]))
    E[Vy[j+1][0]].append((Vy[j + 1][1] - Vy[j][1], Vy[j][0]))
used = [False] * N

# def prim
ans = 0
q = []
heappush(q, (0, 0))
while q:
    dist, now = heappop(q)
    if used[now]:
        continue
    used[now] = True
    ans += dist
    for w, nxt in E[now]:
        if not used[nxt]:
            heappush(q, (w, nxt))
print(ans)

Measured memory_bytes: 89664
n = int(input())
a = list(map(int,input().split()))
asum = sum(a)
want = 0
prev = 0
for i in range(0,n):
    if i == 0:
        want += a[i]
        prev = a[i]
    else:
        if a[i] > prev:
            prev = a[i]
            want += a[i]
        else:
            want += prev
print(want-asum)

Measured memory_bytes: 32380
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int s;cin>>s;
  set<int> S;
  S.insert(s);
  int now=2;
  while (true) {
    if(s%2==0){
      s=s/2;
    }
    else {
      s=3*s+1;
    }
    // debug(s);
    if(S.count(s)){
      break;
    }
    S.insert(s);
    now++;
    // if(now>5)break;
  }
  print(now);


}


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

int main() {
  int N, X;
  cin >> N >> X;
  
  int L[N];
  for (int i = 0; i < N; i++) cin >> L[i];
  
  int D = 0;
  int ans = 1;
  
  for (int i = 0; i < N; i++) {
    D += L[i];
    if (D <= X) {
      ans++;
    } else {
      break;
    }
  }
  
  cout << ans << endl;
    
}

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

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<int>> S(H);
    for(int i=0; i<H; i++){
        string s;
        cin >> s;
        for(int j=0; j<W; j++) S[i].push_back(s[j] == '#');
    }
    int ans = max(H, W);
    vector<int> h(W);
    for(int i=0; i<H; i++){
        stack<pair<int, int>> st;
        for(int j=0; j<W; j++){
            int pos = j;
            while(st.size() && st.top().first > h[j]){
                auto& p = st.top();
                int res = (p.first+1) * (j-p.second+1);
                ans = max(ans, res);
                pos = p.second;
                st.pop();
            }
            if(st.size() == 0 || st.top().first < h[j]) st.push({h[j], pos});
        }
        if(i<H-1) for(int j=0; j<W-1; j++){
            if((S[i][j] + S[i+1][j] + S[i][j+1] + S[i+1][j+1]) % 2){
                h[j] = 0;
            }else{
                h[j]++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 16384
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#define FOR(i,n,x) for(int i=0;i<n;i+=x)
#define ll long long int 
#define llu unsigned long long int
#define pb(x) push_back(x)
#define mp make_pair
#define vi vector<int>
#define vvi vector<vi>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define max(x,y) (x>y)?x:y
#define min(x,y) (x<y)?x:y 
#define mid(s,e) (s+(e-s)/2)
#define MOD 1000000007
#define MAXI 100000000000009
const int MX = 10010896;
const int lmt = 3164;
const int MAXL = 1000;
const int MAX_MID = 1e5;
using namespace std;

void solve(){
    string a,b;
    cin>>a>>b;
    int cnt=0;
    for(int i=0;i<a.length();i++)
    {
        if(a[i]!=b[i])
        cnt++;
    }
    cout<<cnt;
}

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

Measured memory_bytes: 3780
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll h=in(),a=in();
    cout<<(h+a-1)/a<<endl;
}


Measured memory_bytes: 256