akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

typedef long long ll;

ll inf = 998244353;
ll func[300010] = {0};
ll inv[300010] = {0};

ll mult(ll n, ll m){
	if(m==1) return n%inf;
	else if(m%2==0){
		ll t = mult(n,m/2);
		return (t*t)%inf;
	}else{
		ll t = mult(n,m-1);
		return (t*n)%inf;
	}
}

void functional(ll N){
	for(ll i=0;i<=N;i++){
		if(i==0){
			func[i] = 1;
			inv[i] = 1;
		}
		else{
			func[i] = (i*func[i-1])%inf;
			inv[i] = mult(func[i],inf-2);
		}
	}
}

ll comb(ll n,ll k){
	if(k==0 || n==k) return 1;
	else return (((func[n]*inv[k])%inf)*inv[n-k])%inf;
}

ll N,A,B,K;
int main(){
	cin >> N >> A >> B >> K;
	functional(N);
	ll ans = 0;
	for(ll i=0;i<=N;i++){
		if((K-i*B)%A==0 && K-i*B>=0){
			ll j = (K-i*B)/A;
			if(j<=N) ans += (comb(N,i)*comb(N,j))%inf;
			ans = ans%inf;
		}
	}
	cout << ans << endl;
}

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

#define N 200123
#define mod 1000000007

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    if(fopen("input.in", "r")){
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    string s;
    cin >> s;
    for(int i = 0 ; i < 3 ; i++){
    	if(s[i] == '7') {
    		cout << "Yes\n";
    		return 0;
    	}
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 3644
# ITP1_6_C
count = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
    b, f, r, v = map(int, input().split())
    count[b-1][f-1][r-1] +=  v

for k in range(4):
    if not(ｋ == 0):
        print("####################")
    for j in range(3):
        for i in range(10):
            print(" %d"%(count[k][j][i]), end="")
        print()


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

int main(){
    int64_t k; cin >> k;
    if(k % 2 == 0 or k % 5 == 0) { cout << -1 << endl; return 0; }
    int64_t res = 0, cnt = 0;
    while(true) {
        // cout << cnt << " " << res << endl;
        res = (res * 10 + 7) % k; cnt++;
        if(res == 0) break;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>

#define N 20
#define Q 200

int solve(int,int);
int n,a[N];

int main()
{
  int q,m[Q],ans,i;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)
    {scanf("%d",&m[i]);
      ans=(solve(0,m[i]));
      if(ans==1)printf("yes\n");
      else printf("no\n");
    }
  return 0;
}

int solve(int i,int m)
{
  int res;
  if(m==0)return 1;
  else if(i>=n)return 0;
  else{
    res=(solve(i+1,m)||solve(i+1,m-a[i]));
    return res;
      }
}



Measured memory_bytes: 2104
#include <stdio.h>

#define N_MAX 100

int n, m;
int cards[2][N_MAX * 2], state = 0;

void shuffleWithK(int k){
	int next = state ^ 1;
	int i;
	for(i = 0; i < n * 2; i++){
		cards[next][(i + n * 2 - k) % (n * 2)] = cards[state][i];
	}
	state = next;
	return;
}

void wriffle(void){
	int next = state ^ 1;
	int i;
	for(i = 0; i < n; i++){
		cards[next][i * 2] = cards[state][i];
		cards[next][i * 2 + 1] = cards[state][i + n];
	}
	state = next;
	return;
}

void setCards(void){
	int i;
	for(i = 0; i < n * 2; i++){
		cards[0][i] = i + 1;
	}
	return;
}

void debug_output(void){
	int i;
	for(i = 0; i < n * 2; i++){
		printf("%d ", cards[state][i]);
	}
	putchar('\n');
	return;
}

void output(void){
	int i;
	for(i = 0; i < n * 2; i++){
		printf("%d\n", cards[state][i]);
	}
	return;
}

int main(void){
	int i;
	scanf("%d%d", &n, &m);
	setCards();
	for(i = 0; i < m; i++){
		int k;
		scanf("%d", &k);
		if (k) {
			shuffleWithK(k);
		} else {
			wriffle();
		}
		// debug_output();
	}
	output();
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#ifdef DEBUG
#define debug(x) cerr << #x << " " << x << '\n'
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
int n, a[N], b[N];
ll k;
bool check(ll x)
{
	ll now = k;
	for(int i=1;i<=n;i++)
	{
		ll t = x/b[i];
		now -= max(0ll,a[i]-t);
		if(now<0) return 0;		
	}
	return 1;
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> k;
 	for(int i=1;i<=n;i++) cin >> a[i];
 	for(int i=1;i<=n;i++) cin >> b[i];
 	sort(a+1,a+n+1);
 	sort(b+1,b+n+1,greater<int>());
 	ll l = 0, r = 1e12, ans = -1;
 	while(l<=r)
 	{
 		ll mid = (l+r) >> 1;
 		if(check(mid)) r = mid - 1, ans = mid;
 		else l = mid + 1;
 	}
 	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1920
n, a, b = gets.split.map(&:to_i)
walkmax = b/a	#この値より大きい距離はワープした方がコストが低い
town = gets.split.map(&:to_i)
first = town[0]
cost = 0			#求める答え
emptyflag = 0

lefttown = town.select {|t| t < first}.sort
if lefttown.empty?
	lefttown << -Float::INFINITY 
	emptyflag = 1
end

righttown = town.select {|t| first < t}.sort
if righttown.empty?
	righttown << Float::INFINITY
	emptyflag = 1
end

lefttown.each_cons(2) do |x, y|
	if y-x <= walkmax
		cost += a * (y-x)
	else
		cost += b
	end
end

righttown.each_cons(2) do |x, y|
	if y-x <= walkmax
		cost += a * (y-x)
	else
		cost += b
	end
end

distance = [first - lefttown.last, righttown[0] - first].min
if distance <= walkmax
	cost += a * distance
else
	cost += b
end

if emptyflag == 0
	cost += b
end

puts cost


Measured memory_bytes: 10880
#include <cstdio>
#include <vector>

const long long mod=998244353ll;
const int MSIZE=10000009;
void ad(long long &a,long long b){a+=b;a%=mod;}
void mn(long long &a,long long b){a+=mod-b;a%=mod;}
void ml(long long &a,long long b){a*=b;a%=mod;}
long long sq(long long a){return a*a%mod;}
long long pw(long long a,long long n)
{
  return n==0?1ll:sq(pw(a,n/2))*(n%2==1?a:1ll)%mod;
}
long long iv(long long a){return pw(a,mod-2);}
long long inv[MSIZE],F[MSIZE],iF[MSIZE];

void prev(int N)
{
  inv[0]=0;
  inv[1]=1;
  for(int i=2;i<N;i++){
    inv[i]=(mod-mod/i)*inv[mod%i]%mod;
  }
  F[0]=iF[0]=1;
  for(int i=1;i<N;i++){
    F[i]=F[i-1]*i%mod;
    iF[i]=iF[i-1]*inv[i]%mod;
  }
}

long long Ch(int i,int j)
{
  return F[i]*iF[j]%mod*iF[i-j]%mod;
}

long long p2[MSIZE];

int main()
{
  int n;
  scanf("%d",&n);
  prev(n/2+1);
  p2[0]=1ll;
  for(int i=1;i<=n/2;i++){
    p2[i]=2ll*p2[i-1]%mod;
  }
  std::vector<long long> S(n/2+2);
  S[n/2+1]=0ll;
  for(int i=n/2;i>=0;i--){
    S[i]=(S[i+1]+Ch(n/2,i)*p2[n/2-i]%mod)%mod;
  }
  long long bad=0ll;
  for(int i=0;i<=n/2;i++){
    ad(bad,Ch(n/2,i)*p2[n/2-i]%mod*S[n/2-i+1]%mod);
  }
  printf("%lld\n",(pw(3,n)+2*mod-2*bad)%mod);
  return 0;
}


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

using namespace std;

int main(void) {
  int N; cin >> N;
  vector<int> idx;
  for (int i = 0; i < N; i++) idx.push_back(i);

  double X[N], Y[N];
  double M = 1;
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i];
    M *= i+1;
  }

  double ans = 0;

  do {
    double tmp = 0;
    for (int i = 0; i < N-1; i++) {
      tmp += sqrt(pow(X[idx[i]]-X[idx[i+1]], 2.0) + pow(Y[idx[i]]-Y[idx[i+1]], 2.0));
    }
    
    ans += tmp / M;

  } while (next_permutation(idx.begin(), idx.end()));

  cout << fixed << setprecision(6) << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define bear ryan
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define ends ' '
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;

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

const ll inf = 1e9;
const int maxn = 2e5 + 10;

int n, k, c, m, g[maxn];
vector<int> v;
char s[maxn];
bool d[maxn];

int main(void) {
    fastio;
    cin >> n >> k >> c >> s + 1;
    for(int i = 1; i <= n; ++i) if(s[i] == 'o') v.eb(i);
    m = v.size();
    if(m == 0)  return 0;
    int h = v[0];
    g[0] = 1;
    for(int i = 1; i < m; ++i) {
        if(v[i] - h > c) {
            g[i] = g[i - 1] + 1;
            h = v[i];
        }
        else    g[i] = g[i - 1];
    }
    if(g[m - 1] > k)    return 0;
    for(int i = m - 1; i >= 0; --i) {
        if(g[i] == g[m - 1]) {
            d[i] = true;
            continue;
        }
        auto it = lower_bound(all(v), v[i] + c + 1);
        int j = it - v.begin();
        if(it == v.end() || g[i] + 1 < g[j] || !d[j])   d[i] = false;
        else    d[i] = true;
    }

    for(int i = 0; i < m; ++i) if(i == 0 || g[i] != g[i - 1]) {
        if(g[i] != g[i + 1] || !d[i + 1])   cout << v[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3572
#include<stdio.h>
#include<string.h>

int main(void){
  int N,i,j,flg=0;
  char words[100][256];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%s",words[i]);
    if(i!=0 &&words[i][0]!=words[i-1][strlen(words[i-1])-1]){
      printf("No");
      flg=1;
      break;
    }
    for(j=0;j<i;j++){
      if(strcmp(words[i],words[j])==0){
        printf("No");
        flg=1;
        break;
      }
    }
  }
  if(flg!=1){
    printf("Yes");
  }
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int mod = 1e9 + 7;
const int inv2 = (mod + 1) / 2;

inline int add(int a, int b) {
  return a+b >= mod ? a+b-mod : a+b;
}

inline int sub(int a, int b) {
  return a >= b ? a-b : a-b+mod;
}

inline int mul(int a, int b) {
  return llint(a)*b % mod;
}

int powmod(int a, int b) {
  if (b == 0) return 1;
  if (b&1) return mul(a, powmod(a, b-1));
  return powmod(mul(a, a), b/2);
}

const int MAX = 200100;

int L[MAX], Lc[MAX];

void addv(int x, int v) {
  for (++x; x < MAX; x += x&-x) {
    L[x] = add(L[x], v);
    Lc[x]++;
  }
}


void subv(int x, int v) {
  for (++x; x < MAX; x += x&-x) {
    L[x] = sub(L[x], v);
    //    Lc[x]--;
  }
}

pair<int, int> sumv(int x) {
  int r = 0;
  int rc = 0;
  for (++x; x; x -= x&-x) {
    r = add(r, L[x]);
    rc += Lc[x];
  }
  return {r, rc};
}

int main(void) {
  int N;
  scanf("%d", &N);
  vector<int> A(N);
  REP(i, N) scanf("%d", &A[i]);

  vector<pair<int, int>> P(N);
  REP(i, N) P[i] = {A[i], i};

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

  int total = 1;
  REP(i, N) {
    if (P[i].first - i > 0) {
      total = mul(total, P[i].first - i);
    } else {
      printf("0\n");
      return 0;
    }
  }

  vector<int> F(N+1), G(N+1);
  F[N] = G[N] = 1;
  for (int i = N-1; i >= 0; --i) {
    F[i] = mul(F[i + 1], (P[i].first - i));
    G[i] = mul(G[i + 1], max(1, P[i].first - i - 1));
  }

  int ret = 0;
  int j = N-1;
  int sum = 0;
  for (int i = N-1; i >= 0; --i) {
    int cnt = P[i].first - i - 1;
    cnt = mul(cnt, mul(F[0], powmod(F[i+1], mod-2)));
    cnt = mul(cnt, G[i+1]);
    //    TRACE(cnt _ sum _ j);
    ret = add(ret, mul(mul(cnt, sum), inv2));
    // TRACE(ret);
    pair<int, int> below = sumv(P[i].second);
    ret = add(ret, mul(below.second, total));
    ret = sub(ret, mul(below.first, cnt));

    // TRACE(P[i].second _ ret);
    int vi = mul(F[i+1], powmod(G[i], mod-2));
    sum = add(sum, vi);
    addv(P[i].second, vi);
    // TRACE("vi" _ vi);


    if (P[i].first - i - 1 == 0) {
      while (j > i) {
        int vj = mul(F[j+1], powmod(G[j], mod-2));
        sum = sub(sum, vj);
        subv(P[j].second, vj);
        j--;
      }


    }
  }

  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 5760
N=int(input())
x=['']*N
y=['']*N
dic={(0,0):0}
for i in range(N):
    x[i],y[i]=map(int,input().split())

for i in range(N):
    for j in range(N):
        if i==j:
            continue
        else:
            p=y[j]-y[i]
            q=x[j]-x[i]
            if (p,q) in dic.keys():
                dic[(p,q)] += 1
            else:
                dic[(p,q)] = 1

print(N-max(dic.values()))

Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {
    public static void main(String[] args)
    {
        int n,p;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        p = sc.nextInt();
        int odd = 0;
        int even = 0;
        for(int i = 0;i < n;i++)
            if(sc.nextInt() % 2 == 0)
                even++;
            else
                odd++;
        if(p == 0)
            System.out.println(((long) Math.pow(2,even)) * choice(odd,0));
        else
            System.out.println(((long) Math.pow(2,even)) * choice(odd,1));
    }
    private static long choice(int n ,int nd)
    {
        long counter = 0;
        while(n >= nd)
        {
            int ndd = nd;
            if(ndd > n / 2)
                ndd = n - nd;
            counter += p(n,ndd) / p(ndd,ndd);
            nd += 2;
        }
        return counter;
    }
    private static long p(int n,int e)
    {
        long counter = 1;
        for(int i = 0;i < e;i++)
        {
            counter *= n;
            n--;
        }
        return counter;
    }
}


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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

const int N_MAX = 200010;
ll Per[N_MAX] = {}; // n!
ll Per_inv[N_MAX] = {}; //(n!)^-1

ll nCr(ll n, ll r){
    if(n<r) return 0;
 
    if (n == r || r == 0)
        return 1;
    else
        return Per[n] * Per_inv[n-r] % mod * Per_inv[r] % mod;  
}
 
// a^b mod p
ll mod_pow(ll a, ll b){
    if(b==0) return 1;
 
    // 肩が奇数
    if(b%2==1){
        return a * mod_pow(a, b-1) % mod;
    }
    else{
        return mod_pow(a*a % mod, b/2) % mod;
    }
}

void prepare_nCr(){
    // nCr高速化準備
    Per[1] = 1;
    FOR(i, 2, N_MAX){
        Per[i] = i * Per[i-1] % mod;
    }
    Per_inv[1] = 1;
    FOR(i, 2, N_MAX){
        Per_inv[i] = mod_pow(Per[i], 1000000005);
    }
}

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    ll N, M, K;
    cin >> N >> M >> K;
    prepare_nCr();

    ll ans = 0;

    // x方向
    FOR(dx, 1, N){
        ans += dx * (N-dx) % mod * M % mod * M % mod * nCr(M*N-2, K-2) % mod;
        ans %= mod;
    }

    // y
    FOR(dy, 1, M){        
        ans += dy * (M-dy) % mod * N % mod * N % mod * nCr(M*N-2, K-2) % mod;
        ans %= mod;
    }

    p(ans);
    
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>

int main(){
  int N;
  int A,min=2000000000,max=0;

  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&A);
    if(A<min)
      min=A;
    if(A>max)
      max=A;
  }
  
  printf("%d\n",max-min);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
int main(){
  int N;  cin>>N;
  string s;
  N %= 10;
  if(N%10==3){
    s="bon";
  }else if(N==0||N==1||N==6||N==8){
    s="pon";
  }else{
    s="hon";
  }
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
#define MAX 1000000

typedef struct{

  int x,y,z;

}Tree;


Tree A[MAX];

int Dep(int);

main(){

  int i,j,n,num,deg,c,k=0;


  scanf("%d",&n);

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

    A[i].x = -1;
    A[i].y = -1;
    A[i].z = -1;
  }


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

    scanf("%d%d",&num,&deg);

    for(j = 0; j < deg; j++){

      scanf("%d",&c);

      if(j == 0)A[num].y = c;

      else A[k].z = c;

      k = c;
      A[c].x = num;

    }
  }


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

    printf("node %d: parent = %d, depth = %d,",i,A[i].x,Dep(i));

    if(Dep(i) == 0) printf(" root, [");

    else if(A[i].y == -1) printf(" leaf, [");

    else printf(" internal node, [");

    j = A[i].y;

    while(j != -1){

      printf("%d",j);

      j = A[j].z;

      if(j != -1){

	printf(", ");
      }
    }

    printf("]\n");
  }

  return 0;
}



int Dep(int num){

  int dep = 0;

  while(A[num].x != -1){

    num = A[num].x;
    dep++;
  }

  return dep;
}
      
	  
	



Measured memory_bytes: 2908
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
#include<cassert>
using namespace std;
using lint = long long;
using ld = long double;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(lint i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<string> s(n);
	REP(i, n) cin >> s[i];
	lint ans = 0;
	REP(i, n) REP(j, s[i].size() - 1) {
		if(s[i].substr(j, 2) == "AB") ans++;
	}
	int ba = 0, ea = 0, be = 0;
	REP(i, n) {
		if(s[i][0] == 'B' && s[i][(int)s[i].size() - 1] == 'A') ba++;
		else if(s[i][0] == 'B') be++;
		else if(s[i][(int)s[i].size() - 1] == 'A') ea++;
 	}
	if(ba > 0) {
		ans += ba - 1;
		if(ea > 0) {
			ans++;
			ea--;
		}
		if(be > 0) {
			ans++;
			be--;
		}
	}
	ans += min(ea, be);
	cout << ans << endl;
	return 0;
}
/* --------------------------------------- */


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

int main(){
  int h,w; cin>>h >>w;
  string s[h];
  for(int i=0;i<h;i++){
    cin>>s[i];
  }
  
  int dx[8]={-1,-1,-1,0,0,1,1,1};
  int dy[8]={-1,0,1,-1,1,-1,0,1};
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#')continue;
      int cnt=0;
      for(int k=0;k<8;k++){
        const int ni=i+dy[k];
        const int nj=j+dx[k];
        if(ni>=0&&ni<h&&nj>=0&&nj<w){
          if(s[ni][nj]=='#')cnt++;
        }
      }
      s[i][j]=char(cnt+'0');
    }
  }
  for(int i=0;i<h;i++){
    cout<<s[i]<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  string s;cin>>s;s+="9";
  int ans=0;
  string pre;
  for(int i=0;i<s.size();i++){
    if(s.substr(i,1)!=pre){
      pre=s.substr(i,1);
      ans++;continue;
    }
    else {
      pre=s.substr(i,2);
      ans++;
      i++;
    }
  }
  cout<<ans-1<<endl;
}


Measured memory_bytes: 640
#!/usr/bin/env python3
import sys
from heapq import heappush, heappop, heapify
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return [LIST() for _ in range(n)]

def main():
    H, W, K = MAP()
    HH = max(H, W) + 2
    x1, y1, x2, y2 = LIST()
    c = [[-1] + [0 if c == "." else -1 for c in input()] + [-1]
         for i in range(H)]
    c = [[-1] * (W + 2)] + c + [[-1] * (W + 2)]

    # 0123: 上下左右
    stack = []
    heappush(stack, (0, x1, y1, 0))
    heappush(stack, (0, x1, y1, 1))
    heappush(stack, (0, x1, y1, 2))
    heappush(stack, (0, x1, y1, 3))
    DX = (1, 0, -1, 0)
    DY = (0, 1, 0, -1)
    while stack:
        new_stack = []
        while stack:
            curr, x, y, d = heappop(stack)
            flag = True
            a = curr + 1
            for k in range(1, K + 1):
                xx, yy = x + k * DX[d], y + k * DY[d]
                if c[xx][yy] == 0:
                    b = c[xx + DX[(d - 1) % 4]][yy + DY[(d - 1) % 4]]
                    if b == 0 or b == a + 1:
                        heappush(new_stack, (a, xx, yy, (d - 1) % 4))
                    b = c[xx + DX[(d + 1) % 4]][yy + DY[(d + 1) % 4]]
                    if b == 0 or b == a + 1:
                        heappush(new_stack, (a, xx, yy, (d + 1) % 4))
                    c[xx][yy] = a
                elif c[xx][yy] != a:
                    flag = False
                    break
            if flag:
                heappush(new_stack, (a, xx, yy, d))
            if c[x2][y2] > 0:
                print(c[x2][y2])
                return
        stack = new_stack

    print(-1)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 32732
#include<bits/stdc++.h>
using namespace std;
long long qpow(long long a,long long b)
{
	long long ans=1;
	while(b)
	{
		if(b&1)
			ans=ans*a;
		a=a*a;
		b=b/2;
	}
	return ans;
}
int main()
{
	long long n,p;
	cin>>n>>p;
	long long m=sqrt(p);
	if(n==1 || p==1)
		cout<<p<<endl;
	else
	{
		long long ans=1;
		for(long long j=2;j<=m;j++)
		{
			while(p%(long long)pow(j,n)==0)
			{
				p=p/(long long)pow(j,n);
				ans=ans*j;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int n,m,s,t;
queue<int> q;
bool visit[303030];
int dist[303030];
vector <int> graph[303030];

void make_edge(int u, int v)
{
	graph[u*3].push_back(v*3+1);
	graph[u*3+1].push_back(v*3+2);
	graph[u*3+2].push_back(v*3);
}

int main()
{
	usecppio
	cin >> n >> m;
	memset(dist,-1,sizeof(dist));
	for (int i = 0; i<m; i++)
	{
		int u, v;
		cin >> u >> v;
		make_edge(u,v);
	}
	cin >> s >> t;
	q.push(s*3);
	dist[s*3] = 0;
	while(!q.empty())
	{
		int x = q.front();
		q.pop();
		for (auto it:graph[x])
		{
			if (!visit[it])
			{
				q.push(it);
				dist[it] = dist[x]+1;
				visit[it] = 1;
			}
		}
	}
	cout << (dist[t*3]==-1?-1:dist[t*3]/3);
}

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

using ll = long long;
using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(false)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YN(x)         cout << ((x) ? "YES" : "NO") << endl
#define Yn(x)         cout << ((x) ? "Yes" : "No") << endl
#define yn(x)         cout << ((x) ? "yes" : "no") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;

ll gcd(ll a, ll b) { return __gcd(a, b); }
ll lcm(ll a, ll b) { return (a == 0 || b == 0) ? 0 : (a / __gcd(a, b) * b); }

int main(int argc, const char* argv[]) {
	ll n;
	cin >> n;
	
	double ret = 0.0;

	rep(i, n) {
		double a;
		cin >> a;
		ret += 1.0/a;
	}

	cout << setprecision(10) << 1.0/ret << endl;

	return 0;
}


Measured memory_bytes: 256
N,K = map(int, input().split())
P = list(map(int, input().split()))
S=0
for i in range(K):
    S += (P[i]+1)/2.
ans = S
for i in range(N-K):
    S += (P[i+K]-P[i])/2.
    ans = S if S > ans else ans 

print(ans)


Measured memory_bytes: 25060
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

#define int long long

#if defined(__GNUC__)
#define __int32 __int32_t
#endif // __GNUC__

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); (i)++)
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); (i)++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort(ALL(x))
#define RSORT(x, T) sort(ALL(x), greater<(T)>())
#define REVERCE(x) reverce(ALL(x))

#define INT_POW(x, y) [](int a, int b){int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)

itn main() {
	ios::sync_with_stdio(false);

	int n;

	cin >> n;



	cout << (n * n);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    vector<vector<int>> ans(H, vector<int>(W, 1000));
    for(int i = h - 1; i < H; i += h){
        for(int j = w - 1; j < W; j += w){
            ans[i][j] = -1000 * (h * w - 1) - 1;
        }
    }
    if(accumulate(all(ans), 0, [](int a, vector<int> b){return a + accumulate(all(b), 0);}) <= 0){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    for(int i = 0; i < H; i++){
        array_output(all(ans[i]));
    }
}


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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

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

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  ll q;
  cin >> q;

  multiset<ll> s;
  ll offset = 0;
  ll l = 0;
  ll r = 0;
  ll v = 0;
  multiset<ll>::iterator it;

  rep(i, q) {
    ll query;
    cin >> query;
    if (query == 1) {
      ll a, b;
      cin >> a >> b;
      s.insert(a);
      offset += b;

      if (i == 0) {
        it = s.begin();
      } else {
        v += abs(*it - a);

        if (a < *it)
          l++;
        else
          r++;

        ll ox = *it;
        if (r - 1 > l) {
          it++;
          ll nx = *it;
          v -= abs(nx - ox) * (abs(r - l) - 1);

          l++;
          r--;
        } else if (l > r) {
          it--;
          ll nx = *it;
          v -= abs(nx - ox) * (abs(r - l) - 1);
          l--;
          r++;
        }
      }
    } else {
      ll x = *it, y = v + offset;

      cout << x << " " << y << endl;
    }
  }

  return 0;
}


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

vector<vector<int>> g;
vector<int> o;
map<int, int> ad;
vector<ll> c;

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

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}

	return d;
}

int arr[50] = {};

int main(void) {

	int n;
	cin >> n;



	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	sort(arr,arr+n);

	double v = arr[0];
	for (int i = 1; i < n; i++) {
		v += arr[i];
		v /= 2;
	}

	cout << v << endl;

	return 0;
}

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

ps = list(map(int, input().split()))

upper_ans = 0

for i in range(x, 102):
    if not (i in ps):
        upper_ans = i
        break

lower_ans = 0

for j in reversed(range(0, x + 1)):
    if not (j in ps):
        lower_ans = j
        break

if (upper_ans == 0) and (lower_ans == 0):
    ans = 0
elif abs(x - upper_ans) < abs(x - lower_ans):
    ans = upper_ans
elif abs(x - upper_ans) > abs(x - lower_ans):
    ans = lower_ans
else:
    ans = min(upper_ans, lower_ans)

print(ans)


Measured memory_bytes: 9132
#include<stdio.h>  
#include<string.h>  
int x[15],l[15],r[15];  
int kase;  
void dfs(int i,int j,int k)//i 是当前下落的球，j是左?的桶的第几个球，k 是右?放入  
{  
    if(i>10)//如果可以全部下落，肯定?足  
    {  
        kase=1;  
        return;  
    }  
    if(kase)  
    {  
        return;  
    }  
    if(x[i]>l[j-1])//??落在左?  
    {  
        l[j]=x[i];dfs(i+1,j+1,k);  
    }  
    if(x[i]>r[k-1])//??落在右?  
    {  
        r[k]=x[i];dfs(i+1,j,k+1);  
    }  
}  
int main()  
{  
    int t;   
    //freopen("shuju.txt","r",stdin);  
    scanf("%d",&t);  
    while(t--)  
    {  
        for(int i=1;i<=10;++i)  
        {  
            scanf("%d",&x[i]);  
        }  
        kase=0;  
        dfs(1,1,1);  
        if(kase)  
        {  
            printf("YES\n");  
        }  
        else  
        {  
            printf("NO\n");  
        }  
    }  
    return 0;  
}   

Measured memory_bytes: 2508
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int K, A, B;
    cin >> K;
    cin >> A >> B;

    for (int i = A; i <= B; ++i)
    {
        if (i % K == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;

    return 0;
}


Measured memory_bytes: 3636
n, m = map(int, input().split())
ways = [list(map(int, input().split())) for _ in range(m)]
graph = [[] for _ in range(n)]
for way in ways:
    graph[way[0]-1].append(way[1]-1)
    graph[way[1]-1].append(way[0]-1)
dist = [-1 for _ in range(n)]
dist[0] = 0
que = []
que.append(0)
while (len(que) > 0):
    v = que.pop(0)
    for i in graph[v]:
        if dist[i] != -1:
            continue
        dist[i] = dist[v] + 1
        que.append(i)
print('Yes')
for i in range(1, n):
    for j in graph[i]:
        if dist[j] == dist[i] - 1:
            print(j+1)
            break        


Measured memory_bytes: 69940
#include<bits/stdc++.h>
const int N=305,mo=998244353;
inline void add(int&a,const int&b){a+=b-mo;a+=a>>31&mo;}
int n,i,j,k,f[N][N][N],x,ans=mo-1;
char c[N];
bool g[N][N][N];
int main(){
	scanf("%s",c+1);n=strlen(c+1);
	f[0][0][0]=1;
	for(i=0;i<=n;++i)for(j=0;j<=n;++j)for(k=0;k<=n;++k){
		x=f[i][j][k];
		add(f[i+1][j][k],x);
		add(c[n-i]=='1'?f[i][j+1][k]:f[i][j][k+1],x);
	}
	g[0][0][0]=1;
	for(i=0;i<=n;++i)for(j=n;j>=0;--j)for(k=n;k>=0;--k)if(g[i][j][k]){
		if(j)g[i][j-1][k]=1;if(k)g[i][j][k-1]=1;
		g[i+1][j][k]=1;
		if(c[i+1]=='0' && k)g[i+1][j+1][k-1]=1;
		if(c[i+1]=='1' && j)g[i+1][j-1][k+1]=1;
		if(i+2<=n){
			if(c[i+1]=='0' || c[i+2]=='0')g[i+2][j+1][k]=1;
			if(c[i+1]=='1' || c[i+2]=='1')g[i+2][j][k+1]=1;
		}
		add(ans,f[n-i][j][k]);
	}
	printf("%d\n",ans);
}

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

using namespace std;


void solve(long long A, long long B, long long C)
{
    cout << min(C, B/A) << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long A;
    cin >> A;
    long long B;
    cin >> B;
    long long C;
    cin >> C;
    solve(A, B, C);
    return 0;
}


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

int mp[50000] = {};

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    int q;
    cin >> q;
    int m[q];
    rep(i, q) cin >> m[i];
    for (ll bit = 0; bit < (1<<n); bit++){
        int ans = 0;
        rep(i, n){
            if (bit & (1<<i)) ans += a[i];
        }
        mp[ans]++;
    }

    rep(j, q) {
        if (mp[m[j]] > 0) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;
	if (n % 2) {
		rep(i, m) { cout << 1 + i << " " << n - i << endl; }
	} else {
		rep(i, m) {
			if (i % 2) {
				cout << n / 2 - i / 2 << " " << (n + 1) / 2 + 2 + i / 2 << endl;
			} else {
				cout << ((1 + n - i / 2) % n == 0 ? n : (1 + n - i / 2) % n) << " " << 2 + i / 2
				     << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>

using namespace std;
typedef long long ll;
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;}
const ll INF = 1e18+1;


int main() {
  
   int N;
    cin >> N;
 
    for (int i = 1; i < 10; i++) {
        int tmp = N;
        if (tmp % i == 0) {
            if (tmp / i <= 9) {
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";

    
}

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

struct Edge {
	int to;
	long double dist{1};
};
using EdgeVec = std::vector<Edge>;
using EdgeLists = std::vector<EdgeVec>;

///////////////////
// ダイクストラ法 //
///////////////////

// 負辺を含まないグラフの最短経路アルゴリズム
// Edgeは{to, dist}
template <typename Metric = decltype(Edge::dist)>
std::vector<Metric> dijkstra(const EdgeLists& edges, const int source)
{
	std::vector<Metric> distance(edges.size(), std::numeric_limits<Metric>::max());
	using DistPoint = std::pair<Metric, int>;
	std::priority_queue<DistPoint, std::vector<DistPoint>, std::greater<DistPoint>> updatedQueue;
	distance[source] = 0;
	updatedQueue.push({0, source});
	while (!updatedQueue.empty())
	{
		DistPoint now{updatedQueue.top()};
		updatedQueue.pop();
		if (now.first > distance[now.second]) continue;
		for (const Edge& next: edges[now.second])
			if (now.first + next.dist < distance[next.to])
			{
				distance[next.to] = now.first + next.dist;
				updatedQueue.push({distance[next.to], next.to});
			}
	}
	return std::move(distance);
}

int main()
{
	using Point = std::complex<long double>;
	Point start, goal;
	{
		long double x[2], y[2];
		for (int i{}; i < 2; i++)
			scanf("%Lf%Lf", x + i, y + i);
		start = {x[0], y[0]};
		goal = {x[1], y[1]};
	}
	int N;
	scanf("%d", &N);
	std::vector<Point> points(N);
	std::vector<long double> r(N);
	for (int i{}; i < N; i++)
	{
		long double x, y;
		scanf("%Lf%Lf%Lf", &x, &y, &r[i]);
		points[i] = {x, y};
	}
	// {points, start, goal}
	EdgeLists edges(N + 2);
	for (int i{}; i < N; i++)
		for (int j{}; j < N; j++)
		{
			if (i == j) continue;
			edges[i].push_back({j, std::max<long double>(0, std::abs(points[i] - points[j]) - r[i] - r[j])});
		}
	for (int i{}; i < N; i++)
	{
		edges[N].push_back({i, std::max<long double>(0, std::abs(points[i] - start) - r[i])});
		edges[i].push_back({N + 1, std::max<long double>(0, std::abs(points[i] - goal) - r[i])});
	}
	edges[N].push_back({N + 1, std::max<long double>(0.0, std::abs(start - goal))});
	auto distance{dijkstra<long double>(edges, N)};
	printf("%.10Lf\n", distance[N + 1]);

	return 0;
}

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

using namespace std;

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

#define INF 2<<29
#define F first
#define S second

int main(){
  int n,d;
  int sum,ans=0;
  int x[11][11];
  
  scanf("%d %d",&n,&d);
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      scanf("%d",&x[i][j]);
    }
  }

  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      sum=0;
      for(int k=0;k<d;k++){
	sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      if((int)sqrt(sum)*(int)sqrt(sum)==sum) ans++;
    }
  }

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


Measured memory_bytes: 256
/*2019/07/29 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
typedef long long int ll;
void llswap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}
/*
int asc_t(const void *a,const void *b){return ((user_t*)a)->score - ((user_t*)b)->score;}
int desc_t(const void *a,const void *b){return ((user_t*)b)->score - ((user_t*)a)->score;}
*/

int main(){
    char s[50];
    int s_list[50]={};

    scanf("%s",s);
    for(int i=0;s[i]!='\0';i++){
        s_list[s[i]-'a']++;
        if(s_list[s[i]-'a']>1){
            printf("no\n");
            return 0;
        }
    }
    printf("yes\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define all(v) (v).begin(), (v).end()

struct line
{
    int left, right;

    line(int L, int R)
    {
        left = L, right = R;
    }

    const int operator<(const line &L)
    {
        return (left == L.left ? right < L.right : left < L.left);
    }
};

int main()
{
    int no_of_cards, no_of_lines;
    cin >> no_of_cards >> no_of_lines;

    const int oo = 1e9 + 9;
    int largest_left = -oo, smallest_right = oo;

    vector <line> lines;
    for(int i = 1; i <= no_of_lines; i++)
    {
        int left, right;
        cin >> left >> right;

        lines.push_back(line(left, right));

        largest_left = max(largest_left, left);
        smallest_right = min(smallest_right, right);
    }

    int covered_length = (smallest_right < largest_left ? 0 : smallest_right - (largest_left - 1));

    cout << covered_length;
    return 0;
}


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

long long modnum = 1e9 + 7;
int MAX = 510000;
std::vector< long long > fac(MAX);
std::vector< long long > finv(MAX);
std::vector< long long > inv(MAX);

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 % modnum;
        inv[i] = modnum - inv[modnum%i] * (modnum / i) % modnum;
        finv[i] = finv[i - 1] * inv[i] % modnum;
    }
}

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] % modnum) % modnum;
}

int main(){
    int N, K;
    std::cin >> N >> K;
    std::vector< int > A(N);
    for(int i=0; i<N; i++){
        std::cin >> A[i];
    }
    
    COMinit();
    std::sort(A.begin(), A.end());
    
    long long p = 0;
    long long m = 0;
    for(int i=0; i<N-K+1; i++){
        long long tmp_m = (A[i] * COM(N - i - 1, K - 1)) % modnum;
        long long tmp_p = (A[N - i - 1] * COM(N - i - 1, K - 1)) % modnum;
        if(p + tmp_p < 0){
            p = p + tmp_p + modnum;
        }else{
            p = (p + tmp_p) % modnum;
        }
        if(m + tmp_m < 0){
            m = m + tmp_m + modnum;
        }else{
            m = (m + tmp_m) % modnum;
        }
    }
    if(p < m){
        p += modnum;
    }
    
    std::cout << p - m << std::endl;
    
    return 0;
}



Measured memory_bytes: 12544
import java.util.*;

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

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

        int[] array = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        Arrays.sort(array);

        long ans = 0;

        for (int i = 0; i < n; i++) {
            if (k >= n) {
                break;
            }

            if (i < n - k) {
                ans += array[i];
            } else {
                break;
            }
        }

        System.out.println(ans);

    }
}

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

int main() {
 int a, b;
 cin>>a>>b;
 if(a+b==15){
	 cout<<"+"<<endl;
 }else if(a*b==15){
	 cout<<"*"<<endl;
 }else{
	 cout<<"x"<<endl;
 }
	return 0;
}



Measured memory_bytes: 256
using System;

namespace aoj6c
{
    class Program
    {
        static void Main(string[] args)
        {
            /*b?£?f??????r???????????¨?±????v???*/
            int[,,] member = new int[5,4,11];   //4?£????3????????????10??¨?±? [0]????????¨?????????
            int n = int.Parse(Console.ReadLine());

            for(int i = 1; i <= n; i++)
            {
                string[] data = (Console.ReadLine()).Split(' ');
                int b = int.Parse(data[0]);
                int f = int.Parse(data[1]);
                int r = int.Parse(data[2]);
                int v = int.Parse(data[3]);
                member[b,f,r] += v ;
            }
            for( int l = 1; l <= 4; l++)
            {
                for (int j = 1; j <= 3; j++)
                {
                    for (int k = 1; k <= 10; k++)
                    {
                        Console.Write(" " + member[l, j, k]);
                    }
                    Console.WriteLine();
                }
                if( l != 4)
                {
                    Console.WriteLine("####################");

                }
            }
        }
    }
}

Measured memory_bytes: 9108
#include<stdio.h>
main()
{
	char s[3] , i;
	int a=0, b=0, c=0;
	gets(s);
	for(i=0;s[i]!='\0';i++)
	{
		if (s[i]=='a')
a=a+1;
		if (s[i]=='c')
c=c+1;
		if (s[i]=='b')
b=b+1;
	}
	if (a==1 && b==1 && c==1)
	printf("Yes");
	else
	printf("No");
	return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,s1;
  cin >> s >> s1;
  rep(i,s.size()){
    cout << s[i];
    if(i < s1.size())
      cout << s1[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,t;bool f=1;
  cin>>s>>t;
  int n = s.size();
  for(int i=0;i<n;++i)
  {
    if(s[i]!=t[i])
    {f=0;break;}
  }
  cout<<(f?"Yes\n":"No\n");
  return 0;
}

Measured memory_bytes: 3624