akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
int main(void){
    // Your code here!
    
    int n;
    cin>>n;
    
    
    if(n%2==1){
        cout<<0;
        return 0;
    }
    ll ans=0;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin>>vec[i];
    } 
    sort(vec.begin(), vec.end());
    
    ll mid= n/2;
    ans= vec[mid]- vec[mid-1];
    
    cout<<ans;
}


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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(ll i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
//Write From this Line

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

	//解法:b[i]に対して、aはどこまで行けるか見る。
	//b[i]にたいしてcが何個行けるか
	ll ans = 0 ;
	rep(i,n){
		//b[i] - 1 以下となるものの個数を数える。
		ll a_index = lower_bound(a.begin(),a.end(), ll(b[i] )) - a.begin();
		ll c_index = lower_bound(c.begin(),c.end(), ll(b[i] + 1)) - c.begin();
		ans += (a_index)* (n -c_index); 
	}
	cout << ans << endl;
}


Measured memory_bytes: 2560
/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-12-15 21:01:22
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

string S;

int main()
{
  cin >> S;
  ll ans = 0;
  ll black = 0;
  for (auto x : S)
  {
    if (x == 'B')
    {
      black++;
    }
    else
    {
      ans += black;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
package main

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

func solve() {
	n, k := getInt(), getInt()
	ans := 0

	x := n / k
	ans += pow(x, 3)

	if k%2 == 0 {
		y := n/(k/2) - x
		ans += pow(y, 3)
	}

	fmt.Fprintln(wr, ans)
}

func pow(a, b int) int {
	ret := 1
	for i := 0; i < b; i++ {
		ret *= a
	}
	return ret
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


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

namespace TYC
{
	const int N = 2e5 + 5;

	int n, tot, C[N], Fa[N], M[N], R[N], Q[N][2];
	vector<int> E[N];
	struct node {  int ls, rs, v; } tr[N * 150];

	int add(const int p, const int x, const int w, const int l = 1, const int r = n)
	{
		int o = ++tot;
		tr[o] = tr[p];
		if (l == r)
			return tr[o].v += w, o;
		int mid = (l + r) >> 1;
		if (x <= mid)
			tr[o].ls = add(tr[p].ls, x, w, l, mid);
		else
			tr[o].rs = add(tr[p].rs, x, w, mid + 1, r);
		tr[o].v = tr[tr[o].ls].v + tr[tr[o].rs].v;
		return o;
	}

	int merge(const int x, const int y, const int l = 1, const int r = n)
	{
		if (!x || !y)
			return x + y;
		int o = ++tot;
		if (l != r)
		{
			int mid = (l + r) >> 1;
			tr[o].ls = merge(tr[x].ls, tr[y].ls, l, mid);
			tr[o].rs = merge(tr[x].rs, tr[y].rs, mid + 1, r);
		}
		tr[o].v = tr[x].v + tr[y].v;
		return o;
	}

	int del(const int p, const int v, const int l = 1, const int r = n)
	{
		if (r <= v)
			return 0;
		if (l == r)
			return p;
		int o = ++tot, mid = (l + r) >> 1;
		if (v <= mid)
		{
			tr[o].ls = del(tr[p].ls, v, l, mid);
			tr[o].rs = tr[p].rs;
		}
		else
		{
			tr[o].ls = 0;
			tr[o].rs = del(tr[p].rs, v, mid + 1, r);
		}
		tr[o].v = tr[tr[o].ls].v + tr[tr[o].rs].v;
		return o;
	}

	int query(const int o, const int x, const int l = 1, const int r = n)
	{
		if (!o) 
			return 0;
		if (l == r)
			return tr[o].v;
		int mid = (l + r) >> 1;
		if (x <= mid)
			return query(tr[o].ls, x, l, mid);
		else
			return tr[tr[o].ls].v + query(tr[o].rs, x, mid + 1, r);
	}

	void dfs(const int u, const int f)
	{
		Fa[u] = f;
		M[u] = max(M[f], f);
		for (int v : E[u])
			if (v != f)
			{
				dfs(v, u);
				R[u] = merge(R[u], R[v]);
			}
		Q[u][0] = query(R[u], M[u]) + 1;
		Q[u][1] = query(R[u], M[f]) + 1;
		int t = query(R[u], u) + 1;
		R[u] = del(R[u], u);
		R[u] = add(R[u], u, t);
	}

	void dfs(const int u)
	{
		if (u != 1)
			C[u] = C[Fa[u]] + Q[u][0] - (u < M[u] && u < M[Fa[u]] ? Q[u][1] : 0);
		for (int v : E[u])
			if (v != Fa[u])
				dfs(v);
	}

	void work()
	{
		scanf("%d", &n);
		for (int i = 1, u, v; i < n; i++)
		{
			scanf("%d%d", &u, &v);
			E[u].push_back(v);
			E[v].push_back(u);
		}
		for (int i = 1; i <= n; i++)
			sort(E[i].begin(), E[i].end());
		dfs(1, 0);
		dfs(1);
		for (int i = 2; i <= n; i++)
			printf("%d ", C[i]);
	}
}

int main()
{
	TYC::work();
	return 0;
}

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

#define LL long long
#define pii pair<int,int>
#define MP make_pair
#define debug(x) cerr<<#x<<": "<<x<<endl;
#define fgx cerr<<"--------------"<<endl;
#define dgx cerr<<"=============="<<endl;

inline int read(){
	int x=0,f=1; char c=getchar();
	for (;!isdigit(c);c=getchar()) if (c=='-') f=-1;
	for (;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}

const int MAXN = 100010; 

vector<pii> E[MAXN];
int N,ans,col[MAXN];
void dfs(int x,int Fa,int lst){
	int Col=0;
	for (auto Nxt : E[x]){
		int y=Nxt.first,z=Nxt.second;
		if (y!=Fa){
			++Col;
			if (Col==col[lst]) ++Col;
			col[z]=Col; dfs(y,x,z);
		}
	} ans=max(ans,Col);
}
int main(){
	N=read();
	for (int i=1;i<N;++i){
		int x=read(),y=read();
		E[x].push_back(MP(y,i));
		E[y].push_back(MP(x,i));
	} dfs(1,0,0);
	printf("%d\n",ans);
	for (int i=1;i<N;++i) printf("%d\n",col[i]);
	return 0;
}


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

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

  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }

  sort(a.begin(), a.end());

  for (int i = 0; i < n; i++) {
    cout << a[i].second << endl;
  }

}

Measured memory_bytes: 1536
#!/usr/bin/env python3

#import
import math
#import numpy as np
N = int(input())
A = list(map(int, input().split()))

class SegTree:
    def __init__(self, segfunc, e, v, init_val = None):
        """
        segfunc: function 区間にしたい操作\n
        e: Any 単位元\n
        v: int or List 要素数か格納する配列\n
        init_val: Any 初期値
        """
        self.segfunc = segfunc
        self.e = e
        self.init_val = init_val if init_val != None else e
        if isinstance(v, int):
            v = [self.init_val] * v
        self.n = len(v)
        self.log = (self.n).bit_length()
        self.size = 1 << self.log
        self.tree = [e] * 2 * self.size
        # 1-indexedなのでtree[1:self.size]がN-1要素
        # tree[self.size:self.size + N]が配列
        for i in range(self.n):
            self.tree[self.size + i] = v[i]
        for i in range(self.size - 1, 0, -1):
            self._update(i)

    def set(self, k, x) -> None:
        """
        k番目の値をxに更新\n
        k: index(0-indexed)\n
        x: update value
        """
        k += self.size
        self.tree[k] = x
        for i in range(1, self.log + 1):
            self._update(k >> i)

    def get(self, k):
        """
        a[k]を返す\n
        k: index(0-indexed)
        """
        assert 0 <= k < self.size
        return self.tree[k + self.size]

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る\n
        l: index(0-indexed)\n
        r: index(0-indexed)
        """
        res = self.e
        l += self.size
        r += self.size
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

    def all_query(self):
        """
        全範囲にsegfuncしたものを得る
        """
        return self.tree[1]

    # 二分探索実装、いる？

    def _update(self, k):
        self.tree[k] = self.segfunc(self.tree[k * 2], self.tree[k * 2 + 1])

seg = SegTree(math.gcd, 0, A)

ans = 0

for i in range(N):
    ans = max(ans, math.gcd(seg.query(0, i), seg.query(i + 1, N)))

print(ans)


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  using ll = long long;
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (auto&& [x, y] : a) {
    cin >> y >> x;
  }
  sort(a.begin(), a.end());
  ll sum = 0;
  bool ok = 1;
  for (auto&& [x, y] : a) {
    sum += y;
    if (sum > x) {
      ok = 0;
      break;
    }
  }
  if (ok) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

constexpr int mod = 1000000007;
class mint {
 public:
  long long x;
  constexpr mint(long long x = 0) : x((x % mod + mod) % mod) {}
  constexpr mint operator-() const { return mint(-x); }
  constexpr mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  constexpr mint& operator-=(const mint& a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  constexpr mint& operator*=(const mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  constexpr mint operator+(const mint& a) const {
    mint res(*this);
    return res += a;
  }
  constexpr mint operator-(const mint& a) const {
    mint res(*this);
    return res -= a;
  }
  constexpr mint operator*(const mint& a) const {
    mint res(*this);
    return res *= a;
  }
  constexpr mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  constexpr mint inv() const { return pow(mod - 2); }
  constexpr mint& operator/=(const mint& a) { return (*this) *= a.inv(); }
  constexpr mint operator/(const mint& a) const {
    mint res(*this);
    return res /= a;
  }
};

ostream& operator<<(ostream& os, const mint& m) {
  os << m.x;
  return os;
}

mint choose(long long n, long long a) {
  mint x, y;
  x.x = 1;
  y.x = 1;
  for (long long i = (0); i < (a); ++i) {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  mint ma = choose(n, a);
  mint mb = choose(n, b);
  mint ans;
  ans.x = 2;
  ans = ans.pow(n);
  ans -= 1;
  ans -= ma;
  ans -= mb;
  cout << ans << endl;
}


Measured memory_bytes: 256
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    S = input()
    p = 'a'
    for c in S:
        if c is p:
            print('Bad')
            break
        else:
            p = c
    else:
        print('Good')

# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc131","a",main)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n;
    ll mod = 1e9 + 7;
    cin >> n;
    if (n == 3) {
        cout << 61 << endl;
        return 0;
    }
    string src = "ATCG";
    unordered_map<string, int> cand;
    int cur_idx = 0;
    auto gen = [&](auto self, int depth, string cur) {
        if (depth == 4) {
            if (cur.find("AGC") != string::npos)
                return;
            for(int i = 1; i < 4; i++) {
                string s2 = cur;
                swap(s2[i], s2[i-1]);
                if (s2.find("AGC") != string::npos)
                    return;
            }
            // cand.insert(cur);
            cand[cur] = cur_idx++;
            return;
        }
        for(int i = 0; i < 4; i++)
            self(self, depth+1, cur+src[i]);
    };
    string tmp = "";
    gen(gen, 0, tmp);
    vector<ll> dp(cand.size(), 1);
    for(int t = 5; t <= n; t++) {
        vector<ll> nxt_dp(cand.size(), 0);
        for(auto p: cand) {
            for(char c: src) {
                auto nxt = p.first.substr(1) + c;
                if (cand.count(nxt) > 0) {
                    nxt_dp[cand[nxt]] += dp[p.second];
                    nxt_dp[cand[nxt]] %= mod;
                }
            }

        }
        swap(dp, nxt_dp);
    }
    ll ans = 0;
    for(auto& val: dp)
        ans = (ans + val) % mod;

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




Measured memory_bytes: 256
num = []
aaa = []
nmax = 0
n2max = 0
count = 0
n = int(input())
for i in range(n):
    a = int(input())
    aaa.append(a)
    if(nmax < a):
        n2max = nmax
        nmax = a
        count = 1
        num = [i]
    elif(nmax == a):
        count += 1
        num.append(i)
    elif(n2max < a):
        n2max = a
for i in range(len(aaa)):
    if(count >= 2) or (nmax != aaa[i]):
        print(nmax)
    else:
        print(n2max)

Measured memory_bytes: 20384
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

x, y = map(int, input().split())

if (x in a and y in a) or \
    (x in b and y in b) or \
    (x in c and y in c):
    print('Yes')
else:
    print('No')

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

int main(void){
    int n;
    string c;
    cin >> n >> c;
    int r = 0, a = 0;
    for (auto x : c) if (x == 'R') r++;
    for (int i=0; i<r; i++) if (c[i] == 'R') a++;
    cout << r - a << endl;
    return 0;
}

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

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

    // input mass data
    int hi[n];
    for(int i=0;i<n;i++){
        cin >> hi[i];
    }

    int max[n]={0};
    int max_elm = 0;
    int check = hi[0];
    for(int i=1;i<n;i++){
        if(check>=hi[i]) max[max_elm]++;
        else max_elm++;  
        check = hi[i];
    }

    sort(max, max+n,greater<>());
    cout << max[0] << endl;
}

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

#define endl "\n"
#define ioss ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
//#define int long long

typedef  long long ll;

using namespace std;


int main()
{
	ioss	
	int h,a;cin>>h>>a;
  if(h%a==0)cout<<h/a<<endl;
  else cout<<h/a+1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
 
int main(){
    int h, w;
    cin >> h >> w;
    vector<string> c;
    string s;

    rep(i,h){
        cin >> s;
        c.push_back(s);
    }
    rep(i,h){
        cout << c[i] << endl;
        cout << c[i] << endl;
    }

    return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int d[n];
    for (int i = 0; i < n; ++i) cin >> d[i];

    sort(d, d + n);

    cout << d[n/2] - d[n/2-1] << endl;
}

Measured memory_bytes: 640
import heapq

N,M = map(int, input().split())
es = [[] for _ in range(N)]

for i in range(M):
    a,b,c = map(int, input().split())
    es[a-1].append((c, b-1))
    es[b-1].append((c, a-1))

INF = float("inf")
# dp[i][j]:点iからjまでの最短距離
dp = [[INF for _ in range(N)] for _ in range(N)]

# 全点を開始点として探索
for i in range(N):
    # 同じ地点は距離0
    dp[i][i] = 0
    q = []
    # iまで0で行ける、を追加
    heapq.heappush(q,(0,i))
    while q:
        # 最短の候補を取り出す
        c,a = heapq.heappop(q)
        # 候補が最短でなければ捨てる
        if dp[i][a] < c:
            continue
        # 候補が最短になりうるならその点に繋がる辺を調べる
        for nc,b in es[a]:
            # i->b の経路について、i->a->bで行く方が今わかっているコストより小さい時
            if dp[i][b] > dp[i][a] + nc:
                dp[i][b] = dp[i][a] + nc
                # iからbまでdp[i][b]で行けるよ、を追加
                heapq.heappush(q, (dp[i][b],b))


        

ans = 0
for a in range(N):
    for c,b in es[a]:
        if dp[a][b] != c:
            ans += 1

print(ans//2)

Measured memory_bytes: 3568
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    int ans=0;
    int x=1;
    rep(i,n){
        (a[i]!=x?ans:x)++;
    }
    cout<<(ans==n?-1:ans)<<endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

const int INF = 1000000007;
int n;
vector<int> g[200000];
int dist[200000];

void bfs(int s) {
  REP(i, n) dist[i] = INF;
  queue<int> que;
  que.push(s);
  dist[s] = 0;
  while (que.size()) {
    int u = que.front();
    que.pop();
    REP(i, g[u].size()) {
      int v = g[u][i];
      if (dist[v] == INF) {
        que.push(v);
        dist[v] = dist[u] + 1;
      }
    }
  }
}

int main() {
  cin >> n;
  REP(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  bfs(0);
  int diam = 0, x = 0;
  REP(i, n) {
    if (dist[i] == INF) continue;
    if (diam < dist[i]) {
      diam = dist[i];
      x = i;
    }
  }
  bfs(x);
  diam = 0;
  REP(i, n) {
    if (dist[i] == INF) continue;
    diam = max(diam, dist[i]);
  }
  cout << (diam % 3 == 1 ? "Second" : "First") << endl;
  return 0;
}

Measured memory_bytes: 13556
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;

int main()
{
  int d, g;
  cin >> d >> g;
  vector<int> p(d), c(d);
  for (int i = 0; i < d; ++i)
  {
    cin >> p[i] >> c[i];
  }

  int ans = 1000000;
  for (int bit = 0; bit < (1 << d); ++bit)
  {
    int sum = 0, cnt = 0;
    for (int i = 0; i < d; ++i)
    {
      if (bit & (1 << i))
      {
        sum += p[i] * (i + 1) * 100 + c[i];
        cnt += p[i];
      }
    }
    if (sum < g)
    {
      for (int i = d - 1; i >= 0; --i)
      {
        if (sum >= g)
          break;
        if (!(bit & (1 << i)))
        {
          for (int j = 0; j < p[i]; ++j)
          {
            if (sum < g)
            {
              sum += (i + 1) * 100;
              cnt++;
            }
          }
        }
      }
    }
    ans = min(cnt, ans);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
k = int(input())
x = list(map(int, input().split()))

dist = 0
for i in range(n) :
    if x[i] > k - x[i] :
        dist += 2 * (k - x[i])
    else :
        dist += 2 * x[i]
print(dist)


Measured memory_bytes: 9140
// 解説をそのまま写経した感じです

function Main(input){
  input = input.split("\n");
  var n = ~~input[0]
  var v = input[1].split(" ");
  var even = [];
  var odd = [];
  for(var i = 0; i < n; i++){
  	var h = v[i];
    var a = (i%2?odd:even)[h];
    a = a || {val:h,count:0};
    a.count++;
    if(i%2){odd[h]=a}else{even[h]=a};
  }
  even = even.sort((a,b)=>a.count-b.count).reverse().filter(a=>a);
  odd = odd.sort((a,b)=>a.count-b.count).reverse().filter(a=>a);
  // filter : nullを消去
 
  if(even[0].val!=odd[0].val){
  	return n - even[0].count - odd[0].count;
    // 最頻値が異なる
  }
  if(!even[1] && !even[2]){
  	return n/2;
    // 偶奇どちらの副最頻値も存在しない
    // （すべての数字が同じ）
  }
  if(!even[1]){
  	return n - even[0].count - odd[1].count;
    // 偶数番目の副最頻値が存在しない
  }
  if(!odd[1]){
  	return n - even[1].count - odd[0].count;
    // 奇数番目の副最頻値が存在しない
  }
  return Math.min(
  	n - even[0].count - odd[1].count,
    n - even[1].count - odd[0].count
  );
}

if(typeof require !== 'undefined')console.log(Main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 46836
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	long long a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	long long d=a;
	long long e=b;
	long long f=c;
	long long count=0;
	while(1)
	{
		if(a%2||b%2||c%2)
		{
			printf("%d\n",count);
			break;
		}
		long long a1=a/2;
		long long b1=b/2;
		long long c1=c/2;
		a=b1+c1;
		b=a1+c1;
		c=a1+b1;
		count++;
		if((a==d&&e==b&&f==c))
		{
			printf("-1\n");
			break;
		}
	}
	return 0;
}

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

////////////
// ModInt //
////////////

// 四則演算の最も左に存在する値がModIntでなければキャストでバグる
// 例えばx = mint * 1000;やx = ModInt(1000) * mint;はいいがx = 1000 * mint;は駄目。
template<int64_t mod_ = 1'000'000'007>
class ModInt {
private:
	int64_t integer_;

public:
	constexpr ModInt(const int64_t initial_number = 0)
		: integer_(initial_number){}
	
	// 四則演算
	constexpr ModInt operator+(const ModInt& operand) const
	{
		ModInt ret{this->integer_ + operand.integer_};
		if (ret.integer_ >= mod_)
			ret.integer_ -= mod_;
		return ret;
	}
	constexpr ModInt operator-(const ModInt& operand) const
	{
		ModInt ret{this->integer_ - operand.integer_};
		if (ret.integer_ < 0)
			ret.integer_ += mod_;
		return ret;
	}
	constexpr ModInt operator*(const ModInt& operand) const
	{
		return {this->integer_ * operand.integer_ % mod_};
	}
	constexpr ModInt operator/(const ModInt& operand) const
	{
		return *this * (operand ^ (mod_ - 2));
	}

	// 単項演算子
	constexpr ModInt& operator++()
	{
		if (integer_ + 1 == mod_) integer_ = 0;
		else integer_++;
		return *this;
	}

	constexpr ModInt& operator--()
	{
		if (integer_ == 0) integer_ = mod_ - 1;
		else integer_--;
		return *this;
	}

	constexpr ModInt operator+()
	{
		return *this;
	}

	constexpr ModInt operator-()
	{
		if (integer_ == 0) return ModInt(0ll);
		else return ModInt(mod_ - integer_);
	}

	// 累乗
	constexpr ModInt operator^(const int64_t operand) const
	{
		ModInt ret{1}, pow_ope{this->integer_};
		for (int64_t pow{operand}; pow > 0; pow >>= 1)
		{
			if (pow & 1) ret *= pow_ope;
			pow_ope *= pow_ope;
		}
		return ret;
	}

	// 代入
	constexpr ModInt& operator=(const ModInt& operand)
	{
		this->integer_ = operand.integer_;
		return *this;
	}
	constexpr ModInt& operator+=(const ModInt& operand)
	{
		*this = *this + operand;
		return *this;
	}
	constexpr ModInt& operator-=(const ModInt& operand)
	{
		*this = *this - operand;
		return *this;
	}
	constexpr ModInt& operator*=(const ModInt& operand)
	{
		*this = *this * operand;
		return *this;
	}
	constexpr ModInt& operator/=(const ModInt& operand)
	{
		*this = *this / operand;
		return *this;
	}

	// その他
	constexpr operator int64_t() { return integer_; }

	constexpr ModInt getOne() const
	{
		return ModInt(1ll);
	}
	constexpr ModInt getZero() const
	{
		return ModInt(0ll);
	}

	static constexpr int64_t mod{mod_};
};
using Mint = ModInt<>;

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<std::pair<int, int>> ab(2 * N);
	for (auto& e: ab)
		scanf("%d", &e.first);
	for (int i{}; i < N; i++)
		ab[i].second = 1;
	for (int i{N}; i < 2 * N; i++)
		ab[i].second = -1;
	
	std::sort(ab.begin(), ab.end());
	Mint ans(1ll);
	int count{};
	for (auto& e: ab)
	{
		if (count * e.second < 0) ans *= Mint(std::abs(count));
		count += e.second;
	}
	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std ;
const double pi = acos(-1) ;
int main () {
  while(1) {
    int a , b ;
    cin >> a >> b ;
    if(a == 0 && b == 0 ) break;
    for(int i = 0 ; i < a ; i++){
      for(int j = 0 ; j < b ; j++ ){
        cout << '#' ;
      }
      cout << endl ;
    }
    cout << endl ;
  }
}


Measured memory_bytes: 3104
import Control.Applicative (ZipList (..))
import Control.Monad (guard)

main = getLine >>= putStrLn . show . solve . map read . words

solve ns
    | all even ns || all odd ns = solve' 0 ns
    | otherwise                 = solve' 1 $ alignParity ns
  where
    alignParity ns = head $ do
        op <- [ [(+1), (+1), (+0)]
              , [(+1), (+0), (+1)]
              , [(+0), (+1), (+1)]
              ]
        let ns' = getZipList $ ZipList op <*> ZipList ns
        guard $ all even ns' || all odd ns'
        return ns'

solve' n xs =
    let largest = maximum xs
        xs' = map (abs . subtract largest) xs
    in (sum xs') `div` 2 + n


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

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int findSumOfDigits(int n)
{
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

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

    int min = INF_32;
    for (int A = 1; A < N; A++) {
        int B = N - A;
        int sum_A = findSumOfDigits(A);
        int sum_B = findSumOfDigits(B);

        int sum = sum_A + sum_B;
        if (sum < min) {
            min = sum;
        }
    }

    cout << min << endl;
}


Measured memory_bytes: 256
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#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 RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<int> gsba(3), gsbb(3);
		REP(i, 3) {
			cin >> gsba[i];
		}
		REP(i, 3) {
			cin >> gsbb[i];
		}

		vector<LL> dp(n+1);
		REP(i, SZ(dp)) dp[i] = n-i;
		REP(j, 3) {
			int from = gsba[j];
			int to  = gsbb[j];
			RREP(i, n + 1 - from) {
				chmax(dp[i], to + dp[i + from]);
			}
			dpite(ALL(dp));
		}


		int ma = *max_element(ALL(dp));
		{
			vector<LL> dp(ma+1);
			REP(i, SZ(dp)) dp[i] = SZ(dp) - 1 - i;
			REP(j, 3) {
				int from = gsbb[j];
				int to  = gsba[j];
				RREP(i, SZ(dp) - from) {
					chmax(dp[i], to + dp[i + from]);
				}
				dpite(ALL(dp));
			}
			cout << *max_element(ALL(dp)) << endl;
		}

		// LL ans = n;
		// REP(i, n+1) {
		// 	int ado = i;
		// 	int bdo = n-i;
			
		// 	vector<LL> dp(ado + 1);
		// 	REP(i, SZ(dp)) dp[i] = ado-i;
		// 	REP(j, 3) {
		// 		int from = gsba[j];
		// 		int to  = gsbb[j];
		// 		RREP(i, ado + 1 - from) {
		// 			chmax(dp[i], to + dp[i + from]);
		// 		}
		// 		dpite(ALL(dp));
		// 	}

		// 	LL ma0 = 0;
		// 	REP(i, SZ(dp)) {
		// 		chmax(ma0, dp[i]);
		// 	}
		// 	vector<LL> dp2(bdo + 1 + ma0);
		// 	REP(i, SZ(dp2)) dp2[i] = SZ(dp2)-1-i;
		// 	REP(j, 3) {
		// 		int from = gsbb[j];
		// 		int to  = gsba[j];
		// 		RREP(i, bdo + 1 - from) {
		// 			chmax(dp2[i], to + dp2[i + from]);
		// 		}
		// 		dpite(ALL(dp2));
		// 	}


		// 	// int ma1 = 0;
		// 	// REP(i, SZ(dp2)) {

		// 	// }
		// 	// REP(i, SZ(dp)) {
		// 	// 	dp[i] += i;
		// 	// }
		// 	// REP(i, SZ(dp2)) {
		// 	// 	dp2[i] += i;
		// 	// }
		// 	chmax(ans, *max_element(ALL(dp2)));
		// }
		// cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 195584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

ll y[10000005];

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

    for(int i = 0; i < n-1; i++){
        if(a[i] < a[i+1]) {
            kai.pb(a[i]);
            uri.pb(a[i+1]);
        }
    }
    //for(int i:kai) cout << i << endl;
    ll N = uri.size(),money = 1000, kabu = 0;
    rep(i,N){
        kabu += money / kai[i];
        money %= kai[i];
        money += uri[i] * kabu;
        kabu = 0;
    }
    cout << money << endl;
}

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

#define ll long long
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

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

#define M 100001





void solve()
{
    double d,t,s;cin>>d>>t>>s;
    if(d/s <= t)cout<<"Yes";
    else cout<<"No";

}















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

    int t = 1;
    // freopen("intput.txt","w",stdout);

    // cin>>t;
    

    while (t--)
    {

        solve();

    }

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc151() {
	ll N, K, M;
	ll ans;
	cin >> N >> M;

	vector<ll> p(M);
	vector<string> S(M);
	rep(i, M) {
		cin >> p[i] >> S[i];
	}

	ll ac = 0;
	ll pen = 0;

	vector<ll> problem(N, -1);
	vector<bool> is_finish(N, false);
	rep(i, M) {
		if (S[i] == "AC") {
			if (!is_finish[p[i] - 1]) {
				ac++;
				is_finish[p[i] - 1] = true;
				if (problem[p[i] - 1] == -1) {
					problem[p[i] - 1] = 0;
				}
				else {
					pen += problem[p[i] - 1];
				}
			}
		}
		else {
			if (problem[p[i] - 1] == -1) {
				problem[p[i] - 1] = 1;
			}
			else {
				problem[p[i] - 1]++;
			}
		}
	}

	cout << ac << " " << pen << "\n";
}

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

	solve_abc151();

	return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 2e5+5; 
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}

ll raise(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}


int n, q, parent[N], sz[N]; 

int get(int v) {
    if (v==parent[v]) return v;
    return parent[v] = get(parent[v]);
}

void solve()
{
    cin >> n >> q;
    for (int i=1; i<=n; ++i) parent[i]=i, sz[i]=1;
    while (q--) {
        int temp, a, b; cin >> temp >> a >> b;
        if (temp==0) {
            function<void(int,int)> unite = [&](int a, int b) {
                a=get(a);
                b=get(b);
                if (a!=b) {
                    if (sz[a]<sz[b]) swap(a,b);
                    sz[a]+=sz[b];
                    parent[b]=a;
                }
            };

            unite(a,b);
        }else{
            nout(get(a)==get(b)?1:0);
        }
    }
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5132
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import copy

(n, p) = map(int, raw_input().split())
while n!=0 and p!=0:
    bawl = copy.copy(p)
    peb = [0]*n
    for i in range(1000000):
        if bawl > 0:
            bawl -= 1
            peb[i%n] += 1
        else:
            bawl += peb[i%n]
            peb[i%n] = 0

        if bawl == p:
            print i%n
            break
    (n, p) = map(int, raw_input().split())

Measured memory_bytes: 35964
#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

const ll mod = 1e9 + 7;
const int N = 2e5 + 5, M = 1e5 + 5;
const ll INF = 1e18;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;

#define pi acos(-1)

ll fpow(ll a, ll b)
{
	ll res = 1;
	while (b)
	{
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

ll f[N];

int main()
{
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	for (int i = k; i; i--)
	{
		f[i] = fpow(k / i, n);
		for(int j = i * 2; j <= k; j += i)
			f[i] = (f[i] - f[j] + mod) % mod;
		ans = (ans + f[i] * i % mod) % mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4348
#!/usr/bin/perl
use Data::Dumper;
use POSIX qw(floor ceil);

# 引数取り込み
my $a = <>;
my ( $b, $c, $d ) = split( / /, $a );

# 処理開始
my $ans = "No";

$ans = "Yes" if( $b == $c );
$ans = "Yes" if( $c == $d );
$ans = "Yes" if( $d == $b );

$ans = "No" if( $b == $c and $c == $d and $d == $b );

print $ans;

1;

Measured memory_bytes: 7180
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
/*
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int K;
    cin >> K;
    string S = "ACL";
    string ans;
    for (int i = 0; i < K; i++)
        ans += S;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
/* Atcoder Grand Contest 007F
   Pre-calculate the position that t[i] is updated from s[i].
   And for two consecutive pairs (i,j) and (a,b),
   they'll merge into (a-1,j) in one process of merging.
   (Suppose we move greedily in one process.)
   Only using brute-force to simulate won't be enough,
   after p times of merging,we'll get (fi-p,i-p) as our answer.
   And we can determine whether it's ok using binary search then
*/
char s[1000005],t[1000005];
int n,cnt=0;
struct node
{int a,b;
}q[1000005];
int tag[1000005];
int main (){
	int i,cur;
	scanf ("%d",&n);
	scanf ("%s",s+1);
	scanf ("%s",t+1);
	cur=n;cnt=0;
	for (i=1;i<=n;i++)
	{if (s[i]!=t[i]) {break;}
	if (i==n) {printf ("0");return 0;}
	}
	tag[1]=1;
	for (i=2;i<=n;i++)
	{if (t[i]==t[i-1]) {tag[i]=tag[i-1];q[tag[i]].b=i;}
	else {tag[i]=tag[i-1]+1;}
	}
	for (i=n;i>=1;i--)
	{cur=min(cur,i);
	int pos=cur;
	while (cur&&t[i]!=s[cur]) {cur--;}
	if (cur<=0) {printf ("-1\n");return 0;}
	q[tag[i]].a=cur;
	}
	int l=0,r=tag[n],mid;
	while (l<=r)
	{mid=(l+r)>>1;
	int tagw=0;
	for (i=mid+1;i<=tag[n];i++)
	{int t1=q[i].a-mid,t2=q[i-mid].b;
	if (t1<t2) {tagw=1;break;}
	}
	if (tagw==1) {l=mid+1;}
	else {r=mid-1;}
	}
	printf ("%d\n",l);
	return 0;
}
	
	
	
	
	

Measured memory_bytes: 13952
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;

int main() {
  while (true) {
    int n, k;
    cin >> n >> k;
    if (!n && !k) return 0;
    vector<string> v;
    for (int i = 0; i < n; i++) {
      string tmp;
      cin >> tmp;
      v.push_back(tmp);
    }
    sort(v.begin(), v.end());
    set<string> generate;
    do {
      string res;
      for (int i = 0; i < k; i++) {
        res += v[i];
      }
      generate.insert(res);
    } while (next_permutation(v.begin(), v.end()));
    cout << generate.size() << endl;
  }
}



Measured memory_bytes: 3440
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  int n, k;
  cin >> n >> k;
  vector <int> p(n);
  REP(i, n) {
	cin >> p[i];
  }
  sort(all(p));
  int ans = 0;
  REP(i, k) {
	ans += p[i];
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; i++) {
        cin >> S.at(i);
    }
    
    int count;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            count = 0;
            if (S.at(i).at(j) == '#') {
                continue;
            }
            for (int k = -1; k < 2; k++) {
                for (int l = -1; l < 2; l++) {
                    if (i + k < 0 || i + k + 1 > H || j + l < 0 || j + l + 1 > W) {
                        continue;
                    }
                    if (S.at(i + k).at(j + l) == '#') {
                            count++;
                    }
                }
                S.at(i).at(j) = to_string(count).at(0);
            }
        }
    }

    for (int i = 0; i < H; i++) {
        cout << S.at(i) << endl;
    }
}

Measured memory_bytes: 256
from bisect import bisect_right
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

rate = [400, 800, 1200, 1600, 2000, 2400, 2800, 3200]

idx = []

for a in A:
    idx.append(bisect_right(rate, a))

# print(idx)

c = Counter(idx)



min_c = len(c.keys())
if (7 in c.keys()) and (8 in c.keys()):
    min_c -= 1
max_c = 0
for i in range(8):
    if i in c.keys():
        max_c += 1
if 8 in c.keys():
    # min_c -= 1
    # max_c += min(8, c[8])
    max_c += c[8]
    # if max_c > 8:
    #     max_c = 8

print(min_c, max_c)


Measured memory_bytes: 3444
n = int(input())
s = list(input())
t = []
ans = 1
count= []

t = set(s)
t = list(t)

for i in range(len(t)):
    count.append(s.count(t[i]))

for j in range(len(count)):
    ans *= (count[j] + 1)

print((ans-1)%(10**9 + 7))


Measured memory_bytes: 4084
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(), m = scan.nextInt();
		String[] A = new String[n];
		for(int i=0; i<n; i++)A[i]=scan.next();
		String[] B = new String[m];
		for(int i=0; i<m; i++)B[i]=scan.next();

		boolean f = true;
		for(int i=0; i<n-m+1; i++) {
			for(int j=0; j<n-m+1; j++) {
				for(int k=0; k<m; k++) {
					for(int l=0; l<m; l++) {
						if(A[i+k].charAt(j+l) != B[k].charAt(l)) {
							f = false;
							break;
						}
					}
				}
				if(f) {
					System.out.println("Yes");
					System.exit(0);
				}
				f = true;
			}

		}
		System.out.println("No");
	}

}

Measured memory_bytes: 25556
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int max_n = 100000;
const int max_m = 100000;
using namespace std;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい]
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

int main(){
    int N,M; cin >> N>>M;
    UnionFind uni(N);
    REP(i,M){
        int a,b; cin >> a >> b;
        a--;b--;
        uni.connect(a,b);
    }
    int ans = 0;
    REP(i,N){
        ans = max(ans, uni.size(i));
    }

    cout << ans << endl;
}





Measured memory_bytes: 3988
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	int a[3];rep(i,3)cin>>a[i];
	sort(a,a+3);
	if(a[0]!=a[1])cout<<a[0]<<endl;
	else cout<<a[2]<<endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
section=[[] for i in range(M+1)]
for i in range(N):
  l,r=map(int,input().split())
  section[r-l+1].append((l,r))

def add(B,a,s):
    x=a
    while x<=len(B)-1:
        B[x]+=s
        x+=x&(-x)
        
def sums(B,a):
    x=a
    S=0
    while x!=0:
        S+=B[x]
        x-=x&(-x)
    return S

Line=[0]*(M+2)
K=N
for d in range(1,M+1):
  for l,r in section[d]:
    add(Line,l,1)
    add(Line,r+1,-1)
    K-=1
  ans=K
  for s in range(M//d+1):
    ans+=sums(Line,s*d)
  print(ans)





Measured memory_bytes: 88224
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

int max(int a,int b){
    if(a > b){
        return a;
    }else{
        return b;
    }
}

char S[100];

int main(){
    int len;
    for(int i = 0;i < 100;i++){
        scanf("%c",&S[i]);
        if(S[i] == '\n'){
            len = i;
            break;
        }
    }

    int rid = len - 7;
    char go[] = "keyence";
    char keep[7];
    for(int i = 0;i <= 7;i++){
        for(int j = 0;j < i;j++){
            keep[j] = S[j];
        }
        for(int j = rid+i;j < len;j++){
            keep[j-rid] = S[j];
        }
        for(int j = 0;j < 7;j++){
            if(keep[j] != go[j])break;
            if(j == 6){
                printf("YES\n");
                return 0;
            }
        }
    }
    printf("NO\n");
    
    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize "03"
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

signed main() {
	#ifdef LOCAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	IOS;
	int a;	string s;
	cin >> a >> s;
	if(a >= 3200)
		cout << s;
	else
		cout << "red";	
	return 0;
}

Measured memory_bytes: 256
#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 == b) {
    cout << c << endl;
  } else if (b == c) {
    cout << a << endl;
  } else if (a == c) {
    cout << b << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String [] args){
		Scanner in = new Scanner(System.in);
		long n = in.nextLong();
		long b = in.nextLong();
		long r = in.nextLong();
		long bl =0;
		bl+=(n/(b+r))*b;
		long rem = n%(b+r);
		if(rem>b){
			bl+=b;
		}
		else{
			bl+=rem;
		}
		System.out.print(bl);
	}
}

Measured memory_bytes: 23124
fun main() {
  var (x, k, d) = readLine()!!.split(" ").map(String::toLong)
	
  x = Math.abs(x)
  
  k = k - x/d
  
  if(k <= 0L) {
    println(x-d*(k+x/d))
    return
  }
  
  x = x - d*(x/d)
  
  
  if(k%2==0L) {
    println(x)
  } else {
    println(d-x)
  }
}

Measured memory_bytes: 36444
N = input()
S = raw_input()

res = 0
for i in range(N):
	X = set(list(S[:i + 1]))
	Y = set(list(S[i + 1:]))
	c = 0
	for x in X:
		if x in Y:
			c += 1
	if res < c:
		res = c
print res


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


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

    ll db = b/x;
    ll da = a/x;
    ll ans = db-da;
    if(a%x == 0) ans++;

    cout << ans << endl;
}

Measured memory_bytes: 3636
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == "+":
        print(a+b)
    elif op == "-":
        print(a-b)
    elif op == "*":
        print(a*b)
    elif op == "/":
        print(a//b)
    elif op == "?":
        break
    


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

int main() {
    int n, z, w, a[2001], ans;
    cin >> n >> z >> w;
    for (int i = 1; i <= n; i++) cin >> a[i];

    if (n == 1) ans = abs(a[1] - w);
    else ans = max(abs(a[n] - w), abs(a[n] - a[n-1]));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256