akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s;
        cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    int n;
    scanf("%d",&n);
    int w;
    scanf("%d",&w);
    ll a[n+1] = {};
    ll b[n+1] = {};
    srep(i,1,n+1){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    ll dp[n+1][w+1];
    rep(i,n+1){
        rep(j,w+1){
            if(i==0||j==0){
                dp[i][j]=0;
            }else{
                if(a[i]>j){
                    dp[i][j]=dp[i-1][j];
                }else{
                    dp[i][j]=max(dp[i-1][j-a[i]]+b[i],dp[i-1][j]);
                }
            }
        }
    }

    ll ans = 0;
    ans=dp[n][w];
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int H,W;
char grid[404][404];

class UnionFindS{
private:
    vector<int> par;
public:
    UnionFindS(int n){
        par=vector<int>(n,-1);
    }
    int find(int x){
        if(par.at(x)<0) return x;
        else return par.at(x)=find(par.at(x));
    }
    int size(int x){
        return -par.at(find(x));
    }
    void unite(int x, int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(size(x)<size(y)) swap(x,y);
        par.at(x)+=par.at(y);
        par.at(y)=x;
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
};

signed main(){
	cin>>H>>W;
    rep(i,H)rep(j,W)cin>>grid[i][j];
    UnionFindS uni(H*W);
    rep(i,H)rep(j,W){
        if(i>0 and grid[i-1][j]!=grid[i][j])uni.unite(i*W+j,(i-1)*W+j);
        if(i+1<H and grid[i+1][j]!=grid[i][j])uni.unite(i*W+j,(i+1)*W+j);
        if(j>0 and grid[i][j-1]!=grid[i][j])uni.unite(i*W+j,i*W+j-1);
        if(j+1<W and grid[i][j+1]!=grid[i][j])uni.unite(i*W+j,i*W+j+1);
    }
    vector<int> vec(H*W);
    rep(i,H)rep(j,W){
        if(grid[i][j]=='#')vec.at(uni.find(i*W+j))++;
    }
    int ans=0;
    rep(i,H)rep(j,W){
        ans+=(uni.size(i*W+j)-vec.at(i*W+j))*vec.at(i*W+j);
    }
    cout<<ans<<endl;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  int Gate[N+1] = {};
  for(int i=0; i<M; i++){
    int L, R;
    cin >> L >> R;
    Gate[L-1]++;
    Gate[R]--;
  }
  
  int num =0;
  int ans =0;
  for(int i=0; i<N; i++){
    num=num+Gate[i];
    if(num==M) ans++;
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long int ll;

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

  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    if ((i & 1) && (a & 1)) ans++;
  }

  cout << ans << '\n';
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

typedef pair <int, int> ii;

const int Maxn = 1005;
const int Maxm = 200005;
const int mod1 = 1000000007;
const int mod2 = 1000000009;

int n, m;
int a[Maxm], b[Maxm];
vector <ii> neigh[Maxn];
int cur, tim[Maxn], low[Maxn];
int imp[Maxm];
int my[Maxn];
vector <int> S;
bool onStack[Maxn];
int curcol, col[Maxn];
int res[Maxm];
vector <int> gneigh[Maxn];
bool vis[Maxn];
ii ways[Maxn][Maxn];

int Connect(int v)
{
	int res = 0;
	cur++; tim[v] = low[v] = cur;
	my[v] = -1;
	S.push_back(v); onStack[v] = true;
	for (int i = 0; i < neigh[v].size(); i++) {
		ii u = neigh[v][i];
		if (!tim[u.first]) {
			imp[u.second] |= 2;
			res += Connect(u.first); low[v] = min(low[v], low[u.first]);
		} else if (onStack[u.first] && tim[u.first] < low[v]) {
			if (my[v] != -1) imp[my[v]] ^= 1;
			low[v] = tim[u.first];
			imp[u.second] ^= 1; 
			my[v] = u.second;
		}
	}
	if (tim[v] == low[v]) {
		res++;
		curcol++;
		int w;
		do {
			w = S.back(); S.pop_back();
			col[w] = curcol;
			onStack[w] = false;
		} while (w != v);
	}
	return res;
}

int Count(int v, int forb)
{
	int res = 0;
	cur++; tim[v] = low[v] = cur;
	S.push_back(v); onStack[v] = true;
	if (v == b[forb]) {
		int u = a[forb];
		if (!tim[u]) {
			res += Count(u, forb); low[v] = min(low[v], low[u]); 
		} else if (onStack[u] && tim[u] < low[v])
			low[v] = tim[u];
	}
	for (int i = 0; i < neigh[v].size(); i++) {
		ii u = neigh[v][i];
		if (u.second == forb) continue;
		if (!tim[u.first]) {
			res += Count(u.first, forb); low[v] = min(low[v], low[u.first]);
		} else if (onStack[u.first] && tim[u.first] < low[v])
			low[v] = tim[u.first];
	}
	if (tim[v] == low[v]) {
		res++;
		int w;
		do {
			w = S.back(); S.pop_back();
			onStack[w] = false;
		} while (w != v);
	}
	return res;
}

int Count(int forb)
{
	int ans = 0;
	cur = 0;
	fill(tim, tim + Maxn, 0); fill(low, low + Maxn, 0);
	for (int i = 1; i <= n; i++) if (!tim[i])
		ans += Count(i, forb);
	return ans; 
}

void Solve(int v)
{
	if (vis[v]) return;
	vis[v] = true;
	for (int i = 0; i < gneigh[v].size(); i++) {
		int u = gneigh[v][i];
		Solve(u);
		ways[v][u].first = (ways[v][u].first + 1) % mod1;
		ways[v][u].second = (ways[v][u].second + 1) % mod2;
		for (int j = 1; j <= curcol; j++) {
			ways[v][j].first = (ways[v][j].first + ways[u][j].first) % mod1;
			ways[v][j].second = (ways[v][j].second + ways[u][j].second) % mod2;
		}
	}
}

int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= m; i++) {
		scanf("%d %d", &a[i], &b[i]);
		neigh[a[i]].push_back(ii(b[i], i));
	}
	int comp = 0;
	for (int i = 1; i <= n; i++) if (!tim[i])
		comp += Connect(i);
	for (int i = 1; i <= m; i++)
		if (col[a[i]] != col[b[i]]) {
			gneigh[col[a[i]]].push_back(col[b[i]]);
			if (imp[i]) res[i] = Count(i) != comp;
		} else if (imp[i]) res[i] = Count(i) != comp;
	for (int i = 1; i <= n; i++)
		Solve(i);
	for (int i = 1; i <= m; i++) {
		if (!imp[i] && col[a[i]] != col[b[i]])
			res[i] = ways[col[a[i]]][col[b[i]]] != ii(1, 1);
		printf("%s\n", res[i]? "diff": "same");
	}
	return 0;
}

Measured memory_bytes: 15616
N = int(input())
S = list(input())
flg = False

if len(S) == 1:
    flg = False

elif len(S)%2 == 1:
    flg = False
else:
    num = len(S) // 2

    for i in range(num):
        if S[i] == S[i+num]:
            flg = True
        else:
            flg = False
            break

if flg == True:
    print("Yes")

else:
    print("No")

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

struct UnionFind{
    vector<long long> par;

    UnionFind(long long n) : par(n){
        for(long long i = 0; i < n; i++){
            par[i] = i;
        }
    }

    long long root(long long x){
        if(par[x] == x){
            return x;
        }
        return par[x] = root(par[x]);
    }

    void unite(long long x, long long y){
        long long rx = root(x);
        long long ry = root(y);
        if(rx == ry){
            return;
        }

        par[rx] = ry;
    }

    bool same(long long x, long long y){
        long long rx = root(x);
        long long ry = root(y);
        return rx == ry;
    }
};


int main(){
    long long n, m;
    cin >> n >> m;
    vector<long long> p(n);
    
    UnionFind tree(n);

    for(long long i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
    }

    for(long long i = 0; i < m; i++){
        long long x, y;
        cin >> x >> y;
        x--;
        y--;
        tree.unite(x, y);
    }

    long long count = 0;
    for(long long i = 0; i < n; i++){
       if(tree.same(i, p[i]) == true){
           count++;
       }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 4796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;

char s[N];

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> s + 1;
    int n = strlen(s + 1);
    ll ans = 0;
    int cur = 0;
    for(int i = 1; i <= n; i++) {
        if(s[i] == 'B') cur++;
        else {
            ans += cur;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

constexpr int dx[4] = {1, 0, -1, 0};
constexpr int dy[4] = {0, 1, 0, -1};
bool used[405][405];

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

    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i = 0; i < h; ++i)  cin >> s[i];
    vector<vector<int>> a(h, vector<int>(w));
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            a[i][j] = s[i][j] == '#';
        }
    }

    ll ans = 0;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(used[i][j])  continue;
            
            queue<P> que;
            que.push(P(i, j));
            int bcnt = 0, wcnt = 0;

            while(!que.empty()){
                P p = que.front();
                que.pop();
                int x = p.first, y = p.second;
                if(used[x][y])  continue;
                used[x][y] = true;
                bcnt += a[x][y] == 1;
                wcnt += a[x][y] == 0;

                for(int k = 0; k < 4; ++k){
                    int nx = x + dx[k], ny = y + dy[k];
                    if(nx < 0 || nx >= h || ny < 0 || ny >= w)  continue;
                    if(used[nx][ny])    continue;
                    if(a[x][y] == a[nx][ny])    continue;
                    
                    que.push(P(nx, ny));
                }
            }

            ans += (ll)bcnt * wcnt;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	int a, b; cin >> a >> b;
	int ans = max({ a + b,a - b,a * b });
	cout << ans << endl;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int a, b, c, d, e, f, i, j, k, l, s = 0, w = 100;
  cin >> a >> b >> c >> d >> e >> f;
  a *= 100;
  b *= 100;
  for (i = 0; i <= f; i += a)
    for (j = 0; i + j <= f; j += b)
      for (k = 0; i + j + k <= f; k += c)
        for (l = 0; i + j + k + l <= f; l += d)
          if ((k + l) * (100 + e) <= e * (i + j + k + l) &&
              s * (i + j + k + l) <= (k + l) * (w + s))
            w = i + j, s = k + l;
  cout << w + s << " " << s;
}


Measured memory_bytes: 256
import heapq

def binary_search(data, value):
    left = 0            # 探索する範囲の左端を設定
    right = len(data) - 1            # 探索する範囲の右端を設定
    while left <= right:
        mid = (left + right) // 2            # 探索する範囲の中央を計算
        if data[mid] == value:
            # 中央の値と一致した場合は位置を返す
            return mid
        elif data[mid] < value:
            # 中央の値より大きい場合は探索範囲の左を変える
            left = mid + 1
        else:
            # 中央の値より小さい場合は探索範囲の右を変える
            right = mid - 1
    return -1            # 見つからなかった場合

n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
way = [0]
hq = [0]
heapq.heapify(hq)
posi = 0
cycle = 0
while True:
    if binary_search(way, a[posi]) != -1:
        rest = way.index(a[posi])
        cycle -= (rest - 1)
        break
    way.append(a[posi])
    heapq.heappush(hq, a[posi])
    posi = a[posi]
    cycle += 1
# print(way)
# print(cycle)
if k < len(way):
    print(way[k] + 1)
else:
    print(way[(k-rest) % cycle + rest] + 1)

Measured memory_bytes: 110628
package main

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

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

var rdr *bufio.Reader

func main() {
	rdr = bufio.NewReaderSize(os.Stdin, BUFSIZE)
	solve()
}

func solve() {
	var A, B int
	fmt.Scanf("%d %d", &A, &B)
	fmt.Println(gcd(A, B))
}

func readline() string {
	buf := make([]byte, 0, BUFSIZE)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			fmt.Println(e.Error())
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readIntSlice(size int) []int {
	slice := make([]int, size)
	lines := strings.Split(readline(), " ")
	for i, v := range lines {
		slice[i] = s2i(v)
	}
	return slice
}

func readInt64Slice(size int) []int64 {
	slice := make([]int64, size)
	lines := strings.Split(readline(), " ")
	for i, v := range lines {
		slice[i] = s2i64(v)
	}
	return slice
}

func readint() int {
	return s2i(readline())
}

func readint64() int64 {
	return s2i64(readline())
}

// For int64
func b2i64(b bool) int64 {
	if b {
		return 1
	}
	return 0
}

func abs64(v int64) int64 {
	if v < 0 {
		return -v
	}
	return v
}

func min64(values ...int64) int64 {
	ret := int64(INF_INT64)
	for _, v := range values {
		if ret > v {
			ret = v
		}
	}
	return ret
}

func max64(values ...int64) int64 {
	ret := -int64(INF_INT64)
	for _, v := range values {
		if ret < v {
			ret = v
		}
	}
	return ret
}

func s2i64(s string) int64 {
	v, ok := strconv.ParseInt(s, 10, 64)
	if ok != nil {
		panic("Faild : " + s + " can't convert to int64")
	}
	return v
}

// For int
func b2i(b bool) int {
	if b {
		return 1
	}
	return 0
}

func abs(v int) int {
	if v < 0 {
		return -v
	}
	return v
}

func min(values ...int) int {
	ret := INF_INT
	for _, v := range values {
		if ret > v {
			ret = v
		}
	}
	return ret
}

func max(values ...int) int {
	ret := -INF_INT
	for _, v := range values {
		if ret < v {
			ret = v
		}
	}
	return ret
}

func s2i(s string) int {
	v, ok := strconv.Atoi(s)
	if ok != nil {
		panic("Faild : " + s + " can't convert to int")
	}
	return v
}

func lcm(v1, v2 int) int {
	if v1 > v2 {
		v1, v2 = v2, v1
	}
	for v1 != 0 {
		v1, v2 = v2%v1, v1
	}
	return v2
}

func gcd(v1, v2 int) int {
	return v1 * v2 / lcm(v1, v2)
}

/* ------------------------------------------------ */
/* Data stracture                                   */
/* ------------------------------------------------ */
type IntHeap []int

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }


Measured memory_bytes: 2240
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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 Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

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


void Main(){
    ll N;
    cin >> N;
    ll mn = LONG_LONG_MAX;
    FOR(i, 1+sqrt(N), 1){
        if(N%i==0){
            chmin(mn, i+N/i);
        }
    }
    cout << mn-2 << el;
}



Measured memory_bytes: 384
# AOJ 0138 Track and Field Competition
# Python3 2018.6.19 bal4u

q = {}
for i in range(3):
	g = {}
	for j in range(8):
		p, t = list(input().split())
		g[p] = t
	x = list(sorted(g.items(), key=lambda x:x[1]))
	print(*x[0])
	print(*x[1])
	del g[x[0][0]]
	del g[x[1][0]]
	q.update(g)
x = sorted(q.items(), key=lambda x:x[1])
print(*x[0])
print(*x[1])



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

const int MAX = 510000;
const int mod = 1000000007;

long long fac[MAX]; //i!%mod=fac[i]
long long finv[MAX]; //pow(i!,-1)%mod=finv[i]
long long inv[MAX]; //pow(i,-1)%mod=inv[i]

// テーブルを作る前処理
void cominit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main(int argc, char const *argv[])
{
	cominit();
	int n,k;
	cin>>n>>k;
	long long ans=0LL;
	for (int i = 0; i <= min(n,k); ++i)
	{
		ans+=com(n,i)*com(n-1,n-i-1);
		ans%=mod;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;
#define MAX 1000000007

class Calc_Mod{//calculate mod
    public:
        unsigned int mod=1000000007;
        ll plus_mod(ll a,ll b){
            return (a+b)%mod;
        }
        ll minus_mod(ll a,ll b){
            return (a-b)%mod;
        }
        ll multi_mod(ll a,ll b){
            return a*b%mod;
        }
        ll LSM(ll a,int b){//a^b%mod
            queue<int> q;
            while(b>=1){
                q.push(b%2);
                b/=2;
            }
            ll ans=1;
            while(!q.empty()){
                if(q.front()==1){
                    ans=multi_mod(ans,a);
                }
                a=multi_mod(a,a);
                q.pop();
            }
            return ans;
        }
        ll div_mod(ll a,ll b){// a/b
            return multi_mod(a,LSM(b,mod-2));
        }
        ll combi(ll a,ll b){//aCb
            ll ans=1;
            ll kaijo=1;
            rep(i,b){
                ans=multi_mod(ans,a-i);
                kaijo=multi_mod(kaijo,b-i);
            }
            ans=div_mod(ans,kaijo);
            return ans;
        }
        
};

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

    ssort(a);
    cout << a[n-1]-a[0] << endl;
}

Measured memory_bytes: 3604
import math

n = int(input())
c, s, f = [], [], []
for _ in range(n - 1):
    x, y, z = map(int, input().split())
    c.append(x)
    s.append(y)
    f.append(z)

for i in range(n - 1):
    t = 0
    for j in range(i, n - 1):
        t = s[j] + f[j] * max(0, math.ceil((t - s[j]) / f[j])) + c[j]
    print(t)

print(0)

Measured memory_bytes: 3188
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 200100;
int n, pot[MAXN][2];

char s[MAXN];

int cnt[200];

int main() {
  scanf("%s",s);
  n = strlen(s);
  
  ll sol = (ll)n * (n + 1) / 2;
  REP(i, n) cnt[s[i] - 'a']++;
  REP(i, 'z') sol -= (ll)cnt[i] * (cnt[i] + 1) / 2;
  printf("%lld\n",sol + 1);
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a <= c && c <= b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

ll f(ll x) { return x>1?(2*f(x/2)+1):1; }

int main()
{
  ll h;
  cin>>h;
  cout<<f(h)<<endl;
  return 0;
}


Measured memory_bytes: 256
import operator
for e in iter(input,'0'):
    target = [[*map(int,input().split())]for _ in[0]*int(e)]
    bx, by = min(target)
    target = {(x - bx, y - by) for x, y in target}
    max_tx = max(map(operator.itemgetter(0), target))
    b = {tuple(map(int,input().split()))for _ in[0]*int(input())}
    max_sx = max(map(operator.itemgetter(0), b))
    lim_x = max_sx - max_tx
    for x,y in b:
        if x > lim_x:continue
        for u,v in target:
            if (x + u, y + v) not in b:break
        else:
            print(x - bx, y - by)
            break


Measured memory_bytes: 6096
import collections
N = int(input())
  
# 素因数分解
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

num1 = prime_decomposition(N)
num2 = collections.Counter(num1)

ans = 0

for j in set(num1):
  number = 0
  for k in range(50):
    number += k
    if number > num2[j]:
      ans += (k-1)
      break
        
print(ans)

Measured memory_bytes: 9512
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;
int a[110];
int main(void)
{
    string s;
    cin >> s;

    ll ans = 0;
    int idx = 0;
    ll cn1 = 0, cn2 = 0;
    for (int i = s.size() - 1; i >= 0; --i)
    {
        if (s[i] == 'W')
            cn1++;
        else
            ans += cn1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
//\\//\\ * * * //\\// ||
#include <bits/stdc++.h> 

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int n = (int) s.size();
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += s[i] != t[i];
  }
  cout << ans << '\n';
  return 0;
}


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

int main(){
	int x,a,b;
	cin>>x>>a>>b;

	if(-a+b<=0)
		cout<<"delicious"<<endl;
	else if(-a+b<=x)
		cout<<"safe"<<endl;
	else
		cout<<"dangerous"<<endl;
}


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

using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
ll MOD = 1000000007;

int main() {
	ll N; cin >> N;
	ll C[500] = {};
	ll S[500] = {};
	ll F[500] = {};
	rep(i, 0, N - 1) {
		cin >> C[i] >> S[i] >> F[i];
	}

	ll t = 0;
	rep(i, 0, N) {
		t = S[i];
		t += C[i];
		rep(j, i + 1, N -1) {
			t = max(S[j], t);
			if ((t - S[j]) % F[j] != 0) {
				t += F[j] - (t - S[j]) % F[j];
			}
			t += C[j];
		}
		cout << t << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(new BufferedInputStream(System.in));
        int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
       int m=sc.nextInt()-1;
        System.out.println(a[m]);

    }
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

//定数
//円周率
const double pi = 3.141592653589793238462643383279;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000000; // = 10^17
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7
//前処理テーブルの大きさ指定
const int MAX = 1200000; // = 10^6 + 2*(10^5)
//ちなみに、1024MBで持てる最大長の配列は10^8程度

//データ構造
//隣接リスト用構造体（有向グラフ向け）
struct edge {
  ll to; // E.toでその辺の終点へアクセスできる。
  ll cost; // e.costでその辺の重みにアクセスできる。
};
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける。
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す。
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す。
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}

//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  ll ans = -LINF;
  ans = max(ans, A * C);
  ans = max(ans, A * D);
  ans = max(ans, B * C);
  ans = max(ans, B * D);
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <iostream>
using namespace std;

int main() {

  int num[1001], n=0;

  cin >> n;

  for(int i=0; i<n; i++) {

    cin >> num[i];
    
  }

  for(int i=0; i<n; i++) {

    if(num[n-i-1]==num[0]) {

      cout << num[0] << endl;

      break;
      
    }

    cout << num[n-i-1] << " ";

  }
    
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main(){
	ll n,k;
	cin >> n >> k;
  ll ans= 0;

  for (ll i = k; i < n+2; i++)
  {
    ll largest = (i)*(2*n-i+1)/2;
    ll smallest = (i)*(i-1)/2;
    ans+=largest-smallest+1;
  }
  cout << ans%1000000007;
}

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

int main() {
  int n, m, l, a[110][110] = {0}, b[110][110] = {0};
  long long c[110][110] = {0};
  cin >> n >> m >> l;
  for (int i=0;i<n;i++)
    for (int j=0;j<m;j++)
      cin >> a[i][j];
  for (int i=0;i<m;i++)
    for (int j=0;j<l;j++)
      cin >> b[i][j];

  for (int i=0;i<n;i++)
    for (int j=0;j<l;j++)
      for (int k=0;k<m;k++)
        c[i][j] += a[i][k] * b[k][j];
  for (int i=0;i<n;i++) {
    for (int j=0;j<l-1;j++)
      cout << c[i][j] << " ";
    cout << c[i][l-1] << endl;
  }
}



Measured memory_bytes: 3280
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, m;
    cin >> n >> m;
    vector<P> e(m);
    rep(i, m) cin >> e[i].second >> e[i].first;
    sort(all(e));
    int ans = 0, last = -1;
    rep(i, m)
    {
        int l = e[i].second - 1, r = e[i].first - 1;
        if (l <= last && last < r)
            continue;
        last = r - 1;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<u32> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    println!("{}", a.iter().fold(0, |acc, x| acc | x).trailing_zeros());
}


Measured memory_bytes: 4352
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;

// import java.text.DecimalFormat; 
// import java.text.DecimalFormatSymbols; 
 
 
// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
 
public class Main {
    
    public static void main(String args[] ) throws Exception {
        /* Sample code to perform I/O:
         * Use either of these methods for input
 
        //BufferedReader
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String name = br.readLine();                // Reading input from STDIN
        System.out.println("Hi, " + name + ".");    // Writing output to STDOUT
 
        //Scanner
        Scanner s = new Scanner(System.in);
        String name = s.nextLine();                 // Reading input from STDIN
        System.out.println("Hi, " + name + ".");    // Writing output to STDOUT
        
        for Round off
         DecimalFormat deciFormat = new DecimalFormat(); 
        deciFormat.setMaximumFractionDigits(9); 
        */
 
        // Write your code here
        StringBuffer str = new StringBuffer();
        PrintWriter pw=new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int T =Integer.parseInt(br.readLine());
        Map<String,Integer> mp = new HashMap<String,Integer>();
        mp.put("AC",0);
        mp.put("WA",0);
        mp.put("TLE",0);
        mp.put("RE",0);
        while(T-->0){
            String s = br.readLine();
            mp.put(s,mp.get(s)+1);
        }
        str.append("AC x "+mp.get("AC")+"\n");     
        str.append("WA x "+mp.get("WA")+"\n");
        str.append("TLE x "+mp.get("TLE")+"\n");
        str.append("RE x "+mp.get("RE")+"\n");
        
        

        pw.print(str.toString());
        pw.close();
    }
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
    
}

Measured memory_bytes: 44736
fun main() {
    val n = readLine()!!.toInt()
    val mutableList = readLine()!!.split(" ").map { it.toLong() }.toMutableList()
    var cnt = 0

    while (true){
        if (check(mutableList)){
            cnt++
            for (i in mutableList.indices){
                mutableList[i] = mutableList[i] / 2
            }
        } else {
            break
        }
    }
    println(cnt)

}

fun check(list: MutableList<Long>): Boolean{
    val n = list.size
    var cnt = 0

    for (i in list){
        if (i%2==0L){
            cnt++
            if (cnt == n){
                return true
            }
        } else {
            break
        }
    }
    return false
}

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

int main() {
  int n, h, w;
  cin >> n >> h >> w;
  vector<int> a(n);
  vector<int> b(n);
  int cnt = 0;
  for (int i = 0; i < n; i ++) {
    cin >> a.at(i) >> b.at(i);
    if (a.at(i) >= h && b.at(i) >= w) {
      cnt ++;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	long long a[100001],b[100001],c,f=0,n;
	scanf("%lld",&n);
	for(c=0;c<n+1;c++){
		scanf("%lld",&a[c]);
	}
	for(c=0;c<n;c++){
		scanf("%lld",&b[c]);
	}
	for(c=0;c<n;c++){
		if(a[c]>=b[c]){
			f+=b[c];
			b[c]=0;
		}
		else{
			f+=a[c];
			b[c]-=a[c];
		}
		if(a[c+1]>=b[c]){
			f+=b[c];
			a[c+1]-=b[c];
		}
		else{
			f+=a[c+1];
			a[c+1]=0;
		}
	}
	printf("%lld\n",f);
	return 0;
}

Measured memory_bytes: 1664
import java.io.*;
import java.util.*;

public class Main {
  private static int solve(int n, int m, int x, int[] as) {
    int costZero = 0;
    int costN = 0;
    for (int a : as) {
      if (a < x) {
        costZero++;
      } else {
        costN++;
      }
    }
    return Math.min(costZero, costN);
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int m = reader.nextInt();
    int x = reader.nextInt();
    int[] as = reader.nextInt(m);
    out.println(solve(n, m, x, as));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 21332
#include <iostream>
using namespace std;
int main() {
    int num, num1, numb2, list1;
    cin >> num;
    int matrix[num][num] = {};
    for(int i = 0; i < num; i++) {
        cin >> num1 >> numb2;
        for(int i = 0 ; i < numb2; i++) {
            cin >> list1;
            matrix[num1 - 1][list1 - 1] = 1;
        }
    }
    for(int i = 0 ; i < num; i++) {
        for (int p = 0; p < num; p++) {
            if (p != num -1) {
                cout << matrix[i][p] << " ";
            } else cout<<matrix[i][p] << endl;
        }
    }
}


Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	int data[100];
	ll int cnt = 0;
	int n;
	cin >> n;
	REP(i,n) cin >> data[i];
	for(int i=n-2;i>-1;i--){
		REP(j,i+1){
			if(data[j]>data[j+1]) {
				swap(data[j+1],data[j]);
				cnt++;
			}
		}
	}
	REP(i,n){
		if(i!=n-1) cout << data[i] << " ";
		else cout << data[i] << endl;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 1164
/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГИ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define zhfs main
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define re return
#define forn(i, n) for (int i = 1; i <= n; i++)
struct Data
{
	int go[3];
	Data()
	{
		for (int i = 0; i < 3; i++)
		{
			go[i] = i;
		}
	}
	Data(int x)
	{
		go[0] = x;
		go[x] = 3 - x;
		go[3 - x] = 0;
	}
};
Data merge(Data x, Data y)
{
	Data res;
	for (int i = 0; i < 3; i++)
	{
		res.go[i] = y.go[x.go[i]];
	}
	return res;
}
struct segmentTree
{
	vector<Data> t;
	segmentTree(int n)
	{
		t.resize(4 * n + 5);
	}
	void build(const string &s, int v, int tl, int tr)
	{
		if (tl == tr)
		{
			t[v] = Data(s[tl - 1] - 'A' + 1);
		}
		else
		{
			int tm = (tl + tr) >> 1;
			build(s, v + v, tl, tm);
			build(s, v + v + 1, tm + 1, tr);
			t[v] = merge(t[v + v], t[v + v + 1]);
		}
	}
	Data get(int v, int tl, int tr, int l, int r)
	{
		if (r < tl || l > tr) return Data();
		if (tl >= l && tr <= r) return t[v];
		int tm = (tl + tr) / 2;
		return merge(get(v + v, tl, tm, l, r), get(v + v + 1, tm + 1, tr, l, r));
	}
};
const int MAXN = 100 * 1000 + 7;
char s[MAXN];
string getString()
{
	scanf("%s", s);
	return string(s);
}
int zhfs()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	string s = getString();
	int n = (int)s.length();
	string t = getString();
	int m = (int)t.length();
	segmentTree st(n + 1);
	st.build(s, 1, 1, n);
	segmentTree tt(m + 1);
	tt.build(t, 1, 1, m);
	int q;
	scanf("%d", &q);
	for (int qq = 1; qq <= q; qq++)
	{
		int a, b, c, d;
		scanf("%d %d %d %d", &a, &b, &c, &d);
		Data ss = st.get(1, 1, n, a, b);
		Data ttd = tt.get(1, 1, m, c, d);
	//	cerr << ss.go[0] << " " << ttd.go[0] << endl;
		if (ss.go[0] == ttd.go[0])
		{
			puts("YES");
		}
		else
		{
			puts("NO");
		}
	}
}



Measured memory_bytes: 10240
// ITP1_9_C:   Card Game
// 2017.7.28

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

char *gets(char *s);

int main()
{
	char buf[300], *t, *h, *p;
	int taro, hanako;
	int i, n, ret;

	gets(buf);
	n = atoi(buf);
	taro = hanako = 0;
	for (i = 0; i < n; i++) {
		gets(buf); p = buf;

		while (isspace(*p)) p++;
		t = p;
		while (isalpha(*p)) p++;
		*p++ = 0;

		while (isspace(*p)) p++;
		h = p;
		while (isalpha(*p)) p++;
		*p++ = 0;

		ret = strcmp(t, h);
		if (ret > 0) taro += 3;
		else if (ret < 0) hanako += 3;
		else taro++, hanako++;
	}
	printf("%d %d\n", taro, hanako);
	return 0;
}

Measured memory_bytes: 536
#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

#define MOD 1000000007
#define N 100005

long fac[N], inv[N], finv[N];
void com_init()
{
  fac[0] = 1;
  fac[1] = 1;
  finv[0] = 1;
  finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < N; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long combination(int a, int b)
{
  if (a < b)
    return 0;
  if (a < 0 || b < 0)
    return 0;
  return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int acs(const void *a, const void *b)
{
  return *(long *)a - *(long *)b;
}

int main() {
  int n, k;
  scanf("%d %d", &n ,&k);
  long a[n], ans=0;
  for (int i=0; i<n; i++) scanf("%ld", a+i);
  qsort(a, n, sizeof(long), acs);
  com_init();
  for (int i=0; i<n-k+1; i++) {
    ans -= (a[i]*combination(n-i-1, k-1))%MOD;
    ans %= MOD;
  }
  for (int i=k-1; i<n; i++) {
    ans += (a[i]*combination(i, k-1))%MOD;
    ans %= MOD;
  }
  if (ans < 0) ans += MOD;
  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 3312
#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 = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

ll choose(ll n, ll r){
    if (n < r) return 0;
    ll res = 1;
    for(int i = 1; i <= r; i++){
        res *= n--;
        res /= i;
    }
    return res;
}

int main(){
    int n, m;
    cin >> n >> m;
    VI a(n);
    rep(i,n) cin >> a[i];
    VL sum(n+1);
    rep(i,n) sum[i+1] = sum[i] + a[i];

    ll ans = 0;
    map<int, ll> mp;
    mp[0]++;
    for(int i = 1; i <= n; i++){
        int r = sum[i] % m;
        mp[r]++;
    }

    for(auto m: mp){
        ll cnt = m.second;
        ans += choose(cnt, 2);
    }
    cout << ans << endl;
    return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		int n = Integer.parseInt(str);
		String s = input.readLine( );
		String t = input.readLine( );
		int answer = n * 2;

		for(int i=0; i<n; i++){
			if(s.substring(i).equals(t.substring(0, n-i))){
				answer = answer - (n-i);
				break;
			}
		}

		System.out.println(answer);

	}
}


Measured memory_bytes: 22100
#include<iostream>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define MAX_V 500000
using namespace std;
struct node{
  int id,key;
  node *parent,*left,*right;
  node():key(0),parent(NULL),left(NULL),right(NULL){}
};
node nodes[MAX_V]{};
int id=0;
node* make_binary_tuple(int key){
  nodes[id].key=key;
  return &nodes[id++];
}

void printPreorder(node* n){
  cout<<" "<<n->key;
  if(n->left!=NULL) printPreorder(n->left);
  if(n->right!=NULL) printPreorder(n->right);
}
void printInorder(node* n){
  if(n->left!=NULL) printInorder(n->left);
  cout<<" "<<n->key;
  if(n->right!=NULL) printInorder(n->right);
}

node* tree_insert(node* root, int key){
  node* z=make_binary_tuple(key);
  node* y=NULL;
  node* x=root;
  while(x!=NULL){
    y=x;
    if(z->key<x->key)
      x=x->left;
    else
      x=x->right;
  }
  z->parent=y;
  if(y==NULL)
    root=z;
  else if(z->key<y->key)
    y->left=z;
  else
    y->right=z;
  return root;
}
bool find_key(node* root, int key){
  if(root==NULL) return false;
  if(key>root->key) return find_key(root->right,key);
  if(key<root->key) return find_key(root->left,key);
  return true;
}
int main(){
  node* root=NULL;
  int n; cin>>n;
  REP(i,n){
    string s; cin>>s;
    if(s=="insert"){
      int key; cin>>key;
      root = tree_insert(root,key);
    } else if(s=="print"){
      printInorder(root); cout<<"\n";
      printPreorder(root); cout<<"\n";
    } else if(s=="find"){
      int key; cin>>key;
      if(find_key(root,key)) cout<<"yes\n";
      else cout<<"no\n";
    }
  }
}

Measured memory_bytes: 16832