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


int main() {
  vector<int> N(3);
  
  for(int i; i<3 ; i++){
    cin >> N.at(i);
  }
  
  sort(N.begin(),N.end());
  
  cout << N.at(2) - N.at(0) << endl;
    
}

Measured memory_bytes: 256
import scala.io.{StdIn => in}

object Main extends App {
  val Array(h, w) = in.readLine.split(" ").map(_.toInt)
  val grid = Iterator.continually(in.readLine)
    .take(h)
    .map(_.map(ch => if(ch == '.') true else false).toArray)
    .toArray

  val dx = Array(0, 1, 0, -1)
  val dy = Array(1, 0, -1, 0)
  val withinRange = (i:Int, j:Int, k:Int) =>
    0 <= i + dy(k) && i + dy(k) < h &&
    0 <= j + dx(k) && j + dx(k) < w

  def rec(isCont:Boolean, i:Int, j:Int):Boolean = {
    if(!isCont || i == h ) isCont
    else if(j == w) rec(isCont, i+1, 0)
    else if(!grid(i)(j)) {
      val res = (0 until 4)
        .map(k => if(withinRange(i,j,k)) !grid(i+dy(k))(j+dx(k)) else false)
        .exists(_ == true)
      rec(res, i, j+1)
    }
    else rec(isCont, i, j+1)
  }

  val ans = if(rec(true, 0, 0)) "Yes" else "No"

  println(ans)
}

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

using namespace std;

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int anum, lnum;
  cin >> anum >> lnum;
  cout << ((lnum & 1 || anum * 2 > lnum || anum * 4 < lnum)? "No" : "Yes") << '\n'; 
  return 0;
}


Measured memory_bytes: 3584
#coding:utf-8
MOD = 10 ** 9 + 7
n = int(input())
A = list(map(int, input().split()))
ans = 0
b = 1
for _ in range(60):
    sm = sum(a&b for a in A)
    sm //= b
    ans = (ans + sm * (n-sm) * b) % MOD
    b<<=1
print (ans)

Measured memory_bytes: 42212
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <queue>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define sort_key(struct_name,key_name) [](const struct_name &x, const struct_name &y){return x.key_name < y.key_name;}
#define pb(x) push_back(x)
typedef long long ll;
const long long MOD = 1e9 + 7;
using namespace std;

//main
int main(){
    int N,K; cin >> N >> K;
    vector<int> H(N);
    rep(i,N) cin >> H[i];
    int ans = 0;
    rep(i,N) if(H[i]>=K) ans += 1;
    cout << ans << endl;
}



Measured memory_bytes: 640
import math
N, K = (int(i) for i in input().split())
R = N-K

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


for i in range(1, K+1):
    #print(((cmb(K-1, i-1))*cmb(i+1+R-(i-1)-1, R-(i-1)))%(10**9+7))
    if (R+1-i) >=0:
        print(cmb(R+1, i)*cmb(K-1, i-1)%(10**9+7))
    else:
        print(0)


Measured memory_bytes: 49756
#include<iostream>
#include<math.h>
using namespace std;

int isPrime(int num) {
	if (!(num % 2) && (num != 2))return 0;
	for (int i = 3; i <= sqrt(num); i += 2) {
		if (!(num % i))return 0;
	}
	return 1;
}

int main() {
	int n;
	cin >> n;
	int* x = new int[n];
	int result = 0;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
		result += isPrime(x[i]);
	}
	cout << result << endl;
	delete[] x;
	return 0;
}


Measured memory_bytes: 3100
//
// Created by bytedance on 2020/5/12.
//

#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e6 + 5;

char shit[maxn];

int main() {
    int n;
    scanf("%d", &n);
    vector<vector<int>> a(maxn), s(maxn);
    for (int i = 0; i < n; i++) {
        scanf("%s", shit);
        int need = 0, off = 0;
        int l = strlen(shit);
        for (int j = 0; j < l; j++) {
            if (shit[j] == '(') off++;
            else off--;
        }
        if (off >= 0) {
            int t = 0;
            for (int j = 0; j < l; j++) {
                if (shit[j] == '(') t--;
                else t++;
                need = max(need, t);
            }
            a[need].push_back(off);
        } else {
            int t = 0;
            for (int j = l - 1; j >= 0; j--) {
                if (shit[j] == ')') t--;
                else t++;
                need = max(need, t);
            }
            s[need].push_back(-off);
        }
    }
    int suma = 0, cnt = 0, num = 0;
    while (cnt <= suma) {
        for (int i = 0; i < a[cnt].size(); i++) {
            suma += a[cnt][i];
            num++;
        }
        cnt++;
    }
    int sumb = 0;
    cnt = 0;
    while (cnt <= sumb) {
        for (int i = 0; i < s[cnt].size(); i++) {
            sumb += s[cnt][i];
            num++;
        }
        cnt++;
    }
    printf("%s\n", (num == n && suma == sumb) ? "Yes" : "No");
    return 0;
}

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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin >> s >> t;
    int n=s.size();
    int m=t.size();
    vector<string> slist;
    for(int i = 0; i < n-m+1; i++) {
        bool flag=true;
        for(int j = 0; j < m; j++) {
            if(s[i+j]!='?'&&s[i+j]!=t[j]) flag=false;
        }
        if(flag){
            string tmp=s;
            for(int k = 0; k < n; k++) {
                if(k>=i && k<i+m) tmp[k]=t[k-i];
                else if(tmp[k]=='?') tmp[k]='a';
            }
            slist.emplace_back(tmp);
        }
    }
    if(slist.size()==0){
        cout << "UNRESTORABLE" << "\n";
    }
    else{
        sort(slist.begin(),slist.end());
        cout << slist[0] << "\n";
    }

    return 0;
}


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

class data {
public:
	int t, from, to;
	data(int t, int from, int to) : t(t), from(from), to(to) {}
	bool operator<(const data& d) const {
		return t<d.t;
	}
};

int main()
{
	int N, M;
	while (cin >> N >> M, N||M)
	{
		bool infected[20001] = {0};
		infected[1] = true;
		set<data> dt;

		for (int i=0; i<M; i++)
		{
			int t, s, d;
			cin >> t >> s >> d;
			dt.insert(data(t, s, d));
		}

		for (set<data>::iterator i=dt.begin(); i!=dt.end(); i++)
		{
			if (infected[i->from])
				infected[i->to] = true;
		}

		int cnt = 0;
		for (int i=1; i<=N; i++)
			if (infected[i]) cnt++;

		cout << cnt << endl;

	}
	return 0;
}

Measured memory_bytes: 1552
#include <stdio.h>

int main()
{
    int N,A,x;
    scanf("%d %d",&N,&A);
    x=(N%500);
    if(x==0)
    {
        printf("Yes");
    }
    else if(x<=A)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }

    return 0;
}


Measured memory_bytes: 1732
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

int INF = INT_MAX / 100;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int f(string s, int& i) {
	char c = s[i++];
	if (('0' <= c && c <= '9') || (c == 'Z')) {
		int x = c - '0';
		if (c == 'Z') x = 0;
		if (('0' <= s[i] && s[i] <= '9') || (s[i] == 'Z')) {
			if (s[i] != 'Z') x = x * 10 + (s[i] - '0');
			i++;
		}
		return x;
	}
	else {
		i++;
		int x = f(s, i);
		i++;
		int y = f(s, i);
		i++;
		if (c == '_') return min(x, y);
		if (c == '^') return max(x, y);
		return min(x, y);
	}
}

void solve() {
	string s; cin >> s;
	int N = s.length();
	int lb = -1, ub = N;
	while (ub - lb > 1) {
		int mid = (lb + ub) / 2;
		int mi, ma;
		{
			string t = s;
			for (int i = mid; i < N; i++) {
				char& c = t[i];
				if (c == '^') c = '_';
				if ('0' <= c && c <= '9') c = 'Z';
			}
			int i = 0;
			mi = f(t, i);
		}
		{
			string t = "###";
			int unko = 0;
			rep(i, N) {
				char c = s[i];
				if (i < mid) t.pb(c);
				else {
					if ('0' <= c && c <= '9') t.pb('9');
					else {
						char c1 = t.back(), c2 = t[t.length() - 2];
						if (('1' <= c1 && c1 <= '9') && !('0' <= c2 && c2 <= '9'))
							t.pb('9'), i--;
						else if (c == '_') t.pb('^');
						else t.pb(c);
					}
				}
			}
			t.erase(t.begin(), t.begin() + 3);
			int i = 0;
			ma = f(t, i);
		}
		if (mi == ma) ub = mid;
		else lb = mid;
	}
	int i = 0;
	cout << f(s, i) << ' ' << ub << endl;
}

int main() {
	int T; cin >> T;
	while (T--) solve();
}


Measured memory_bytes: 492
#include<bits/stdc++.h>
using namespace std;
int main(){
    int S;
  	cin >> S;
    int L = S/100;
    int R = S%100;
    if(L>=1&&L<=12){
        if(R>=1&&R<=12) cout<<"AMBIGUOUS";
        else cout<<"MMYY";
    }
    else if(R>=1&&R<=12)cout<<"YYMM";
    else cout<<"NA";
    return 0;
}

Measured memory_bytes: 256
import numpy as np
N, M =  (int(i) for i in input().split())

A = []
B = []
for i in range(N):
    a, b = (int(i) for i in input().split())
    A.append(a)
    B.append(b)

A = np.array(A)
B = np.array(B)

argsort = np.argsort(A)

count = M
yen = 0
loop_index = -1
while(count>0):
    loop_index += 1
    if(count - (B[argsort[loop_index]]) > 0):
        yen += (A[argsort[loop_index]]*B[argsort[loop_index]])
        count -= B[argsort[loop_index]]
    else:
        yen += A[argsort[loop_index]]*count
        count = 0

print(yen)

Measured memory_bytes: 20876
#include <algorithm>
#include <string>
#include <sstream>
#include <iostream>
#include <math.h>
#include <random>
#include <cstdio>
using namespace std;

const int LOOP = 10000; //??????????????°
const double EPS = 1e-6; //??????????????¨(?°??????????????????????)
int L;
int N; //???????????±???????????°

//???????????±????????????????????????????????¨?????¨???????¨????????¨??????????
double Evaluate(int r[12]) {
	double val = r[0] + r[N-1];
	for (int i = 0; i < N - 1; i++)
	{
		int a = abs(r[i] - r[i+1]), c = r[i] + r[i+1];
		val += sqrt(c*c - a*a);
	}
	return val;
}

//?????¨?????????????????°???????????¨??????????????????????§???????????±???????
//(????§?????????????true)
bool Changes(int cnt) {
	return cnt < rand()%LOOP;
}

//?????????????????????????????¢??°
//?????????????°??????????????¨?????????????
//int r[12] : ???????????±?????????0??????N-1???????????????????????????????????????????????????????´???????
double Solve(int r[12]) {
	double score = Evaluate(r); //?????¨?????¶???r[]????¨???????????´????????????°
	double mi = score; //???????????§?????¶???????¨???????????°???????????´????????????°
	for (int cnt = 0; cnt < LOOP; cnt++)
	{
		//===============================================

		///random
        int i=rand()%N;
        int j=rand()%N;
        int t=r[i];
        r[i]=r[j];
		r[j]=t;
        score = Evaluate(r);
		if(score<mi){
            mi=score;
		}else{
            if(Changes(cnt)){
                mi=score;
            }else{
                int a=r[i];
                r[i]=r[j];
                r[j]=a;
            }
		}
		//===============================================
	}
	return mi; //????°?????????????
}

//??\?????¢????????????????????¢????????£????????§???????????????
int main() {
    srand(time(NULL));
	while (cin >> L)
	{
		N = 0;
		int r[12];
		string S;
		getline(cin, S);
		stringstream SS(S);
		while (!SS.eof()) SS >> r[N++];

		double ans;
		if (N == 1) ans = r[0]*2;
		else ans = Solve(r);

		if (L - ans + EPS > 0) puts("OK");
		else puts("NA");
	}
	return 0;
}

Measured memory_bytes: 3076
N = int(input())
word_set = set()
valid = True
words = ["" for i in range(N)]
for i in range(N):
    words[i] = input()

word_set.add(words[0])
for i in range(1, N):
    if words[i-1][-1] != words[i][0] or words[i] in word_set:
        valid = False
        break
    word_set.add(words[i])
    
if valid:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
N,K = map(int,input().split())
A = list(map(int,input().split()))
for k in range(K):
    imos = [0] * (N+1)
    for i,a in enumerate(A):
        l = max(0, i-a)
        r = min(N, i+1+a)
        imos[l] += 1
        imos[r] -= 1
    imos[0] = min(N, imos[0])
    for i in range(N):
        imos[i+1] = min(N, imos[i] + imos[i+1])
    A = imos[:-1]
    if all(a==N for a in A):
        break
print(*A)

Measured memory_bytes: 168532
#include<stdio.h>

int dp[50];

int fib(int n){
  if(n==0||n==1) return dp[n]=1;
  if(dp[n]!=-1) return dp[n];
  return dp[n]=fib(n-1)+fib(n-2);
}

int main(){
  int n,i;
  for(i=0;i<50;i++) dp[i]=-1;

  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
}



Measured memory_bytes: 2112
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >> n;
    ll cnt = 0;
    while(true){
      if(cnt*cnt > n)
        break;
      cnt++;
    }
    cnt--;
    cout << cnt*cnt << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod=1000000007;
constexpr ll INF=(1ll<<60);
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}


int main(){
    ll n;cin>>n;
    bool yes=false;
    for(ll i=1;i<=9;i++){
        for(ll j=1;j<=9;j++){
            if(n==i*j) yes=true;
        }
    }

    if(yes) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3600
N,Q=gets.chomp.split.map(&:to_i)
s=gets.chomp.split("")
t,d=[],[]
Q.times do
  tt,dd=gets.chomp.split
  t << tt
  d << dd
end

def out_l(s,t,d,pos)
  0.upto(t.size-1) do |i|
    if t[i] == s[pos]
      if d[i] == 'L'
        pos -= 1
      else
        pos += 1
      end
    end
    if pos < 0
      return true
    elsif pos >= s.size
      return false
    end
  end
  return false
end
def out_r(s,t,d,pos)
  0.upto(t.size-1) do |i|
    if t[i] == s[pos]
      if d[i] == 'L'
        pos -= 1
      else
        pos += 1
      end
    end
    if pos < 0
      return false
    elsif pos >= s.size
      return true
    end
  end
  return false
end

l = 0
r = N-1
mid = (l+r)/2

ans = N

while(l<=r)
  if out_l(s,t,d,mid)
    l = mid + 1
  else
    r = mid - 1
  end
  mid = (l+r)/2
end

#printf("%d %d %d\n",l,r,mid)

if l>=0
  ans -= l
end

l = 0
r = N-1
mid = (l+r)/2

while(l<=r)
  if out_r(s,t,d,mid)
    r = mid - 1
  else
    l = mid + 1
  end
  mid = (l+r)/2
end

#printf("%d %d %d\n",l,r,mid)
if l < N
  ans -= (N-l)
end

puts ans



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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

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 int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <int MOD>
struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
    constexpr Fp operator+(const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator-(const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator*(const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator/(const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator+=(const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator-=(const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator*=(const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator/=(const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator==(const Fp& r) const noexcept { return this->val == r.val; }
    constexpr bool operator!=(const Fp& r) const noexcept { return this->val != r.val; }
    friend constexpr ostream& operator<<(ostream& os, const Fp<MOD>& x) noexcept { return os << x.val; }

    friend constexpr Fp<MOD> modpow(const Fp<MOD>& a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<MOD>;

int main() { 
    string C;
    cin >> C;
    cout << (char)(C[0] + 1) << endl;
    return 0; 
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;

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


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

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void solve() {
        int k, x;
        cin >> k >> x;

        for (int i = x - k + 1; i < x + k; ++i) {
            cout << i << " ";
        }
        cout << endl;

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
// #Sazaの1日1AC
#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
const long long INF=9e15;
const double PI=3.14159265358979323846;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vP=vector<pair<long long, long long>>;
//ショートカット
#define rep(i,n) for(long long i = 0; i < n; i++)
#define rep2(i,k,n) for(long long i = k; i < n; i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mkp make_pair
//入力
#define vin(v,N) for(long long id=0;id<N;id++) cin>>v.at(id)
#define lin(n) long long n;cin>>n
#define chin(x) char x;cin>>x;
#define sin(s) string s;cin>>s;
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1);
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//構造体

/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////


//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(N);lin(M);
  vvl G(N);
  rep(i,M){
  lin(a);lin(b); a--; b--;
  G[a].pb(b);
  G[b].pb(a);
  }

  vvl H(N);

  queue<ll> Q;
  vl res(N, INF);
  Q.push(0);
  vector<bool> undone(N, true);
  while(Q.size() > 0){
    ll u = Q.front(); Q.pop();
    undone[u] = false;
    rep(i, G[u].size()){
      ll v = G[u][i];
      if(undone[v]){
        res[v] = u;
        undone[v] = false;
        Q.push(v);
        //cout << u << " " << v << endl;
      }
    }
  }
  cout << "Yes" << endl;
  for(int i = 1; i < N; i++) cout << res[i] + 1 << endl;
}

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

using namespace std;

#define ld long double
#define ll long long int
#define endl '\n'
#define check_time() cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define INF 0x3f3f3f3f

int main()
{
	fastio();
	ld X,t=0,A=100;
	cin>>X;

	while(1)
	{
		t++;
		A+=(A/100);
		A=floor(A);
		if(A>=X)
			break;
	}
	cout<<t<<endl;
	//check_time();
	return 0;   
}   


Measured memory_bytes: 3808
c = [list(map(int, input().split())) for _ in range(3)]
x = [0]*3
y = [0]*3
for i in range(3):
    y[i] = c[0][i] - x[0]
for i in range(3):
    x[i] = c[i][0] - y[0]
for i in range(3):
    for j in range(3):
        if c[i][j] != x[i] + y[j]:
            print("No")
            exit()
print("Yes")

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

int main() {
    int n, m;
    vector<int> p;
    vector<string> s;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int pin;
        string sin;
        cin >> pin >> sin;
        p.push_back(pin);
        s.push_back(sin);
    }

    int acCount = 0;
    int waCount = 0;
    int tempWaCount = 0;
    vector<bool> ansed(n, false);
    vector<int> waCnt(n, 0);
    for (int i = 0; i < m; i++) {
        int pn = p.at(i) - 1;
        string sn = s.at(i);
        if (sn == "WA") {
            if (!ansed.at(pn)) {
                waCnt.at(pn) += 1;
            }
        } else {
            ansed.at(pn) = true;
        }
    }
    for (int i = 0; i < n; i++) {
        if (ansed.at(i)) {
            acCount++;
            waCount += waCnt.at(i);
        }
    }
    cout << acCount << " " << waCount << endl;
}

Measured memory_bytes: 6512
N = int(input())
AB = [list(map(int, input().split())) for i in range(N)]
CD = [list(map(int, input().split())) for i in range(N)]

AB.sort(reverse=True)
CD.sort()

AB_used = set()
CD_used = set()
for index_ab, ab in enumerate(AB):
    my = float('inf')
    i = -1
    j = -1
    if index_ab in AB_used:
        continue
    for index_cd, cd in enumerate(CD):
        if index_cd in CD_used:
            continue
        if (ab[0] < cd[0]) & (ab[1] < cd[1]) & (cd[1] < my):
            i, j = index_ab, index_cd
            my = cd[1]
    if (i != -1) & (j != -1):
        AB_used.add(i)
        CD_used.add(j)

print(len(AB_used))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <stdint.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/rope>
#define int int_fast64_t

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef pair<int, int> pii;
typedef vector<int> VI;

#define FOR(i, j, k, l) for(int (i) = (j) - ((l) < 0); (l) < 0 ? (i) >= (k) : (i) < (k); (i) += (l))
#define RREP(i, j, k) for(int (i) = (j) - 1; (i) >= (k); --(i))
#define REP(i, j, k) for(int (i) = (j); (i) < (k); ++(i))
//#define VIS(it, con) for(__typeof((con).begin()) (it) = (con).begin(); (it) != (con).end(); ++(it))
#define VIS(x, y) for(__typeof(y.begin()) x = y.begin(); x != y.end(); ++x)
#define ALL(x) (x).begin(), (x).end()
#define MST(a, b) memset((a), (b), sizeof(a))
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fir first
#define sec second
#define endl '\n'

// #define _debug
#ifdef _debug
	#define IOS() (void)0
	#define de(...) cout << __VA_ARGS__
    #define ar(a, s, t) { REP(_i, (s), (t)) de((a)[_i] << ' '); de(endl); }
#else
	#define IOS() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); }
	#define de(...) (void)0
    #define ar(...) (void)0
#endif

const int maxn = 1e5 + 9;
int n, res = 0, a[maxn];

main() {
	IOS();
	cin >> n;
	REP(i, 0, n) cin >> a[i];
	sort(a, a + n);
	REP(i, 1, n) res += min(i, n - i) * 2 * (a[i] - a[i - 1]);
	if(n % 2 == 0) res -= a[n / 2] - a[n / 2 - 1];
	else res -= min(a[n / 2] - a[n / 2 - 1], a[n / 2 + 1] - a[n / 2]);
	cout << res << endl;
}

Measured memory_bytes: 1024
/**
 *    author:  tourist
 *    created: 10.05.2020 20:33:59       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, int> mp;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    ans += mp[i - a];
    mp[i + a] += 1;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 20628
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
#define int long long
priority_queue<int> q;
int n, m, x, sum;
main() {
    DAU
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> x;
        q.emplace(x);
    }
    while (m) {
        if (q.empty())
            m = 0;
        else {
            x = q.top() / 2;
            q.pop();
            --m;
            if (x > 0)
                q.emplace(x);
        }
    }
    while (!q.empty())
        sum += q.top(), q.pop();
    cout << sum;
    PLEC
}


Measured memory_bytes: 4164
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;

const ll maxN = 1e7;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

void build(ll node, ll start, ll end){
	if(start == end)
		segtree[node] = A[start];
	else{
		ll mid = (start + end)/2;
		build(left(node), start, mid);
		build(right(node), mid+1, end);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

void update(ll node, ll start, ll end, ll l, ll r, ll val){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(start > end or l > start or r < end)
		return ;
	else if(start >= l and r >= end){
		segtree[node] += val;
		if(start != end){
			lazy[left(node)] += val;
			lazy[right(node)] += val;
		}
	}
	else{
		ll mid=(start + end)/2;
		update(left(node), start, mid, l, r, val);
		update(right(node), mid+1, end, l, r, val);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

ll sums(ll node, ll start, ll end, ll l, ll r){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(l > end or r < start or start > end)
		return 0;
	if(l <= start and r >= end)
		return segtree[node];
	ll mid = (start+end)/2;
	return sums(left(node), start, mid, l , r) + sums(right(node), mid + 1, end, l , r);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll a, b;
	cin >> a >> b;
	ll cur = 1;
	for(ll i=0; i<a; i++)
		cur *= 100;
	cout << cur*(b+(b==100 ? 1 : 0));
	return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include<stdbool.h>
typedef long long ll;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define swap(a,b) {ll tp=a;a=b;b=tp;}
const ll MOD = 1000000007;

int main(){
    int h,w; scanf("%d%d",&h,&w);
    char s[60][60];
    rep(i,h) scanf("%s",&s[i]);

    rep(i,h) rep(j,w) if(s[i][j]=='.')s[i][j]='0';
    rep(i,h)
        rep(j,w)
            if(s[i][j]=='#')
                rep(k,3) 
                    rep(l,3)
                        if(i-1+k>=0&&i-1+k<h&&j-1+l>=0&&j-1+l<w)
                            if(s[i-1+k][j-1+l]!='#')s[i-1+k][j-1+l]++;

    rep(i,h) {
        printf("%s", s[i]);
        puts("");
    }
}


Measured memory_bytes: 1740
import sys
n = int(input())
a_dict = {i : {0 : [i], 1:[]} for i in range(n)}
for i in range(n):
    a = int(sys.stdin.readline().strip())
    for j in range(a):
        x, y = [int(i) for i in sys.stdin.readline().split()]
        x -= 1
        if y == 1:
            a_dict[i][0].append(x)
        else:
            a_dict[i][1].append(x)
best = 0
for i in range(1 << n):
    true_set = set()
    false_set = set()
    _i = bin(i)[2:].zfill(n)
    for j, k in enumerate(_i[::-1]):
        if k == "1":
            t = a_dict[j][0]
            f = a_dict[j][1]
            if true_set.intersection(set(f)) or false_set.intersection(set(t)):
                true_set = {}
                break
            true_set.update(t)
            false_set.update(f)
    res = "".join(["0" if i not in true_set else "1" for i in range(n)])[::-1]
    res = len(true_set) if res == _i else 0
    best = max(best, res)
print(best)

Measured memory_bytes: 47448
#include <stdio.h>

int main(void)
{
	int b, w[4][13] = { 0 }, n, i;
	char a;

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%c", &a);
		scanf("%c %d", &a, &b);

		if (a =='S')
		{
			w[0][b-1] = 1;
		}
		if (a == 'H')
		{
			w[1][b-1] = 1;
		}
		if (a == 'C')
		{
			w[2][b-1] = 1;
		}
		if (a == 'D')
		{
			w[3][b-1] = 1;
		}
	}
	for (i = 0; i < 13; i++)
	{
		if (w[0][i]==0)
		{
			printf("S %d\n", i+1);
		}
	}
	for (i = 0; i < 13; i++)
	{
		if (w[1][i] == 0)
		{
			printf("H %d\n", i+1);
		}
	}
	for (i = 0; i < 13; i++)
	{
		if (w[2][i] == 0)
		{
			printf("C %d\n", i+1);
		}
	}
	for (i = 0; i < 13; i++)
	{
		if (w[3][i] == 0)
		{
			printf("D %d\n", i+1);
		}
	}
	return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[1005];
int main()
{
	int n,k,i,sum=0;
	scanf("%d %d",&n,&k);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	for(i=1;i<=k;i++){
		sum+=a[i];
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 3824
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int LEN = 1e5 + 5;
const int oo = 1e9;
int head[LEN];
struct edge {
    int vet, next;
} E[LEN * 2];
int i, j, k, n, m, s, t, tot;
bool checkodd, checkval;
int L[LEN], R[LEN], isodd[LEN], ans[LEN];
void add(int u, int v) {
    E[++tot] = (edge){v, head[u]};
    head[u] = tot;
}
void dfs(int u, int pre) {
    for (int e = head[u]; e != -1; e = E[e].next) {
        int v = E[e].vet;
        if (v != pre) {
            if (isodd[v] != -1 && isodd[v] != (isodd[u] ^ 1)) {
                checkodd = false;
            }
            isodd[v] = isodd[u] ^ 1;
            L[v] = max(L[v], L[u] - 1);
            R[v] = min(R[v], R[u] + 1);
            dfs(v, u);
            L[u] = max(L[u], L[v] - 1);
            R[u] = min(R[u], R[v] + 1);
        }
    }
    if (L[u] > R[u]) {
        checkval = false;
    }
}
void dfsans(int u, int pre) {
    for (int e = head[u]; e != -1; e = E[e].next) {
        int v = E[e].vet;
        if (v != pre) {
            if (L[v] <= ans[u] + 1 && ans[u] + 1 <= R[v]) {
                ans[v] = ans[u] + 1;
            } else {
                ans[v] = ans[u] - 1;
            }
            dfsans(v, u);
        }
    }
}
int main() {
    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
        head[i] = -1;
        L[i] = -oo;
        R[i] = oo;
        isodd[i] = -1;
    }
    for (int i = 1; i < n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        add(x, y);
        add(y, x);
    }
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) {
        int x, c;
        scanf("%d %d", &x, &c);
        L[x] = R[x] = c;
        isodd[x] = c % 2;
        s = x;
    }
    checkodd = checkval = true;
    dfs(s, -1);
    if (checkodd == false || checkval == false) {
        puts("No");
        return 0;
    }
    ans[s] = L[s];
    dfsans(s, -1);
    puts("Yes");
    for (int i = 1; i <= n; i++) {
        printf("%d\n", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 9088
a,b,c,k = (int(x) for x in input().split())

#print(a,b,c,k)
sum = 0
flag = -1

if a>=k:
  flag = 1
  sum = k
else:
  sum = a
  k = k-a

if flag==-1:
  if b>=k:
    flag = 1
  else:k = k-b

if flag == -1:
  if c>=k:sum = sum -k
  else: sum = sum -c
    
print(sum)

Measured memory_bytes: 9044
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

const int mod=998244353;
vector<int>dp(3005);
int32_t main(){
	IOS
	int n,m;cin>>n>>m;
	vector<int>a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int ans=0;
	for(int i=0;i<n;i++){
		dp[0]+=1;
		dp[0]%=mod;
		for(int j=m-a[i];j>=0;j--){
			dp[j+a[i]]+=dp[j];
			dp[j+a[i]]%=mod;
		}
		ans+=dp[m];
		ans%=mod;
	}
	cout<<ans;
}
 
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


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

int main(){
  int n,m,k;
  cin>>n>>m>>k;

  bool ans=false;
  for(int i=0; i<=n; i++){
    for(int j=0; j<=m; j++){
      if(i*m+j*n-2*i*j==k){
        ans=true;
        goto end;
      }
    }
  }

  end:;
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	map<int, int> mp;
	int temp;
	for(int i=1; i<n; i++) {
		cin >> temp;
		temp--;
		mp[temp]++;
	}
	for(int i=0; i<n; i++) {
		cout << mp[i] << endl;
	}


  return 0;
}


Measured memory_bytes: 13516
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int mod = 1e9 + 7;
const int inf = 2e18;

signed main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N + 1), B(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> A[i] >> B[i];
    }
    vector<vector<int>> dp(1010, vector<int>(60000, inf));
    dp[0][0] = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= H; j++) {
            dp[i][j] = min(dp[i - 1][j], dp[i][max(0LL, j - A[i])] + B[i]);
        }
    }
    cout << dp[N][H] << endl;
}



Measured memory_bytes: 477440
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

// constexpr inline ll mod = 1'000'000'007;
// constexpr int max_n = 200'000 + 5;

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    int n;
    cin >> n;
    vector<ll> as(n), bs(n);
    ll sum = 0;
    rep(i,n) {
        int a;
        cin >> a;
        a--;
        as[i] = a;
        bs[a]++;
    }

    rep(i,n) {
        sum += bs[i] * (bs[i] - 1) / 2;
    }
    rep(i, n) {
        cout << sum - bs[as[i]] * (bs[as[i]] - 1) / 2 + (bs[as[i]] - 1) * (bs[as[i]] - 2) / 2 << endl;
    }

    return 0;
}


Measured memory_bytes: 6360
#include<bits/stdc++.h>
using namespace std;
int main(){
	vector<pair<int,int>> A(5);int time=0;
	for(int i=0;i<5;i++){
		cin>>A[i].second;
        A[i].first=(A[i].second-1)%10+1;
	}sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
	for(int i=0;i<5;i++){
		time=(time+9)/10*10;
		time+=A[i].second;
	}cout<<time<<endl;
}

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


void solve(long long A, long double B){
    printf("%lld\n", static_cast<ll>(floor(A*B)));
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long double B;
    scanf("%Lf",&B);
    solve(A, B);
    return 0;
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  ll ans = 0;
  for (ll i = 1; i <= n; ++i) {
    if (i%3==0 && i%5==0) continue;
    if (i%3==0) continue;
    if (i%5==0) continue;
    ans += i;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define root sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, q, w, ans = 0, count = 0;
  string s;
  cin >> n >> q;
  cin >> s;
  vector<lli> l(q), r(q), d(n + 1, 0);
  rep(i, 0, n)
  {
    if (i + 1 < n && s[i] == 'A' && s[i + 1] == 'C')
      d[i + 1] = d[i] + 1;
    else
      d[i + 1] = d[i];
  }
  rep(i, 0, q)
  {
    cin >> l[i] >> r[i];
    --l[i];
    --r[i];
    cout << d[r[i]] - d[l[i]] << endl;
  }
}

Measured memory_bytes: 3408
P = 10**9+7
fa = [1]
for i in range(1, 50000):
    fa.append(fa[-1] * i % P)
fainv = [pow(fa[-1], P-2, P)]
for i in range(1, 50000)[::-1]:
    fainv.append(fainv[-1] * i % P)
fainv = fainv[::-1]
p2 = [1]
for _ in range(1, 50000):
    p2.append(p2[-1] * 2 % P)
def F(a, b):
    if a < 0 or b < 0: return 0
    return fa[a+b] * fainv[a] % P * fainv[b] % P

N = int(input())
S = input()
M = len(S)
ans = 0
for i in range(5001):
    for j in range(i + (N + M & 1), min(5001, N-M-i+1), 2):
        a = (N+M-i-j) // 2
        b = a - M
        a -= 1
        ans = (ans + (F(i, j) - F(i-1, j+1)) * (F(a, b) - F(a+1, b-1)) * p2[i+b]) % P

print(ans)



Measured memory_bytes: 46044
#include<stdio.h>
int main(){
	int number[6],i,temp;
	char order[100];

	for(i = 0; i < 6; i++){
	  scanf("%d",&number[i]);
	}
	scanf("%s",order);
	for(i = 0; order[i] != '\0'; i++){
	  if(order[i] == 'N'){
		temp = number[0];
	    number[0] = number[1];
		number[1] = number[5];
		number[5] = number[4];
		number[4] = temp;
	  }
	  if(order[i] == 'S'){
		temp = number[0];
	    number[0] = number[4];
		number[4] = number[5];
		number[5] = number[1];
		number[1] = temp;
	  }
	  if(order[i] == 'E'){
		temp = number[0];
		number[0] = number[3];
		number[3] = number[5];
		number[5] = number[2];
		number[2] = temp;
	  }
	  if(order[i] == 'W'){
		temp = number[0];
		number[0] = number[2];
		number[2] = number[5];
		number[5] = number[3];
		number[3] = temp;
	  }
	}
    printf("%d\n",number[0]);
	
	return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N, K; cin >> N >> K;
    vector<i64> A(N, 0);
    REP(i, K) {
        i64 d;
        cin >> d;
        i64 a;
        REP(j, d) {
            cin >> a;
            A[--a]++;
        }
    }
    i64 cnt = 0;
    REP(i, N) {
        if (A[i] == 0) cnt++;
    }
    cout << cnt << endl;

    return 0;
}

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

bool DP(int k,int a,int b,int c) {
    if (k==0) {
        if (b>a && c>b) return true;
        return false;
    }
    bool res1,res2,res3;
    res1 = DP(k-1,a*2,b,c);
    res2 = DP(k-1,a,b*2,c);
    res3 = DP(k-1,a,b,c*2);

    return (res1 || res2 || res3);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    if (DP(K,A,B,C)) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3644