akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//<(") 
#define ll long long   
using namespace std;
 
typedef pair<ll, ll> ii;
typedef pair<ii, ii> iii;
 
const ll mod = 1e9 + 7;
const ll siz =  2e5 + 10;
const ll base = 32;
const ll MAXX = 1e18;

ll n;
vector<ll> a, b;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("INP.txt", "r", stdin);
	//freopen("OUT.txt", "w", stdout);
	cin >> n;
	a.resize(n); b.resize(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i]; cin >> b[i];
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	
	if (n % 2 != 0) {
		cout << b[n / 2] - a[n / 2] + 1 << '\n';
	}
	else {
		double x = (b[n / 2] + b[n / 2 - 1]) / 2.0;
		double y = (a[n / 2] + a[n / 2 - 1]) / 2.0;
		//cerr << x << ' ' << y << '\n';
		ll ans = 2 * (x - y) + 1;
		//cerr << x << ' ' << y << '\n';
		cout << ans << '\n';
	}
	return 0;
} 

Measured memory_bytes: 6364
#include<iostream>
#include<queue>
#include<vector>
using namespace std;

struct edge{
  long long to;
  long long weight;
  edge(int x,int y):to(x),weight(y){}
};

void solve(){
  int n;cin>>n;
  vector<vector<edge> >graph(n);
  vector<int>distans(n,0);
  vector<bool>seen(n,false);
  queue<int>order;
  for(int i=0;i<n-1;i++){
    long long u,v,w;cin>>u>>v>>w;
    u--;v--;
    graph[u].push_back(edge(v,w));
    graph[v].push_back(edge(u,w));
  }
  order.push(0);
  while(!order.empty()){
    int np=order.front();
    order.pop();
    seen[np]=true;
    for(int i=0;i<graph[np].size();i++){
      if(!seen[graph[np][i].to])order.push(graph[np][i].to);
    }
    for(int i=0;i<graph[np].size();i++){
      if(!seen[graph[np][i].to]){
        distans[graph[np][i].to]=(distans[np]+graph[np][i].weight)%2;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<distans[i]<<endl;
  }
}

int main(){
  solve();
}


Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
int t(int a)
{
	if(a%10==0)
	return a;
	else
	return (a/10+1)*10;
}
int main()
{
	int a[5],ans=0,mn=10,m;
	for(int i=0;i<5;i++)
	{
	cin>>a[i];
	if(a[i]%10!=0)
	  if(a[i]%10<mn)
	  {
	    m=i;
	    mn=a[i]%10;
	  }
   } 
   for(int i=0;i<5;i++)
   if(i!=m)
   ans+=t(a[i]);
   ans+=a[m];
   cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define endl '\n'
using ll=long long;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=510000;
const int mod=1e9+7;
const ll oo=1e18+5;

int n;
vector<pair<long double,long double>> point;

bool check(double x,double y,double rad){
	for(int i=0;i<n;++i){
		double _x=point[i].first;
		double _y=point[i].second;
		double _r=sqrt((x-_x)*(x-_x)+(y-_y)*(y-_y));
		if(_r>rad){
			return 0;
		}
	}
	return 1;
}
		

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	cin>>n;
	point.resize(n);
	for(int i=0;i<n;++i) cin>>point[i].first>>point[i].second;
	double ans=1e18;
	// 3 points
	for(int i=0;i<n;++i){
		for(int j=i+1;j<n;++j){
			for(int k=j+1;k<n;++k){
				double x1=point[i].first,y11=point[i].second,x2=point[j].first,y2=point[j].second,x3=point[k].first,y3=point[k].second;
				double delta=2*(x2-x1)*(y3-y2)-2*(y2-y11)*(x3-x2);
				if(delta){
					double Ox=(y3-y2)*(x2*x2-x1*x1+y2*y2-y11*y11)+(y11-y2)*(x3*x3-x2*x2+y3*y3-y2*y2);
					double Oy=(x2-x3)*(x2*x2-x1*x1+y2*y2-y11*y11)+(x2-x1)*(x3*x3-x2*x2+y3*y3-y2*y2);
					Ox/=delta;
					Oy/=delta;
					double r=sqrt((Ox-x1)*(Ox-x1)+(Oy-y11)*(Oy-y11));
					if(check(Ox,Oy,r)) ans=min(ans,r);
				}
			}
		}
	}
	// 2 points
	for(int i=0;i<n;++i){
		for(int j=i+1;j<n;++j){
			double x1=point[i].first,y11=point[i].second,x2=point[j].first,y2=point[j].second;
			double Ox=(x1+x2)/2.0;
			double Oy=(y11+y2)/2.0;
			double cur_r=0;
			for(int k=0;k<n;++k){
				double xx=abs(Ox-point[k].first);
				double yy=abs(Oy-point[k].second);
				double rr=sqrt(xx*xx+yy*yy);
				cur_r=max(cur_r,rr);
			}
			ans=min(ans,cur_r);
		}
	}
	cout<<setprecision(18)<<ans;
	return 0;
}



Measured memory_bytes: 256
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) begin(V), end(V)
#define ALLR(V) rbegin(V), rend(V)
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec

#ifdef DEBUGGING
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

using namespace std;

using namespace std;

istream& operator >>(istream &is, __int128_t &a) {
    int64_t i;
    is >> i;
    a = i;
    return is;
}

ostream& operator <<(ostream &os, __int128_t a) {
    auto i = (int64_t)a;
    os << i;
    return os;
}

V<__int128_t> dsum;

ll naive(ll N, ll X, ll M, const V<ll> &D) {
    ll pre = X;
    ll idx = 0;
    ll ans = 0;
    for (ll i = 1; i < N; i++) {
        ll cur = pre + D[idx];
        idx = (idx + 1) % D.size();
        if (pre % X < cur % X) ans++;
    }
    return ans;
}

ll solve(const V<ll> &D) {
    __int128_t N, X, M;
    cin >> N >> X >> M;
    // cout << naive((ll)N, (ll)X, (ll)M, D) << endl;
    X %= M;
    dsum[0] = 0;
    __int128_t zero = 0;
    for (ll i = 0; i < D.size(); i++) {
        dsum[i + 1] = dsum[i] + D[i] % M;
        if (D[i] % M == 0) zero++;
    }
    N--;
    __int128_t loop = (N / D.size());
    __int128_t last = X + dsum.back() * loop;
    zero *= loop;
    for (ll i = 0; i < N % D.size(); i++) {
        last += D[i] % M;
        if (D[i] % M == 0) zero++;
    }
    // if (last % M == 0) last--;
    return (N - (ll)(last / M) - zero);
}


int main() {
    ll K, Q;
    cin >> K >> Q;
    V<ll> D(K);
    dsum.resize(K + 1);
    for (ll &e : D) cin >> e;
    while (Q--) cout << solve(D) << endl;
    return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define pi 2.0*acos(0.0)
#define INTM 1e18
#define mod 1000000007
#define FOR(i,j,n)    for(ll i=j;i<n;i++)
#define RFOR(i,j,n)    for(ll i=j;i>=n;i--)

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;

int main(){
    ll a,b;
    cin>>a>>b;
    if(a>8 || b>8) cout<<":("<<endl;
    else cout<<"Yay!"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <map>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
struct fix_point: private T {
  explicit constexpr fix_point(T &&func): T(std::forward<T>(func)) { }
  template <class... Args>
  constexpr decltype(auto) operator () (Args &&... args) const {
    return T::operator()(*this, std::forward<Args>(args)...);
  }
};

constexpr int64_t inf = (1ll << 60);

int solve() {
  int64_t N, A, B, C, D;
  std::cin >> N >> A >> B >> C >> D;
  std::map<int64_t, int64_t> dp;
  dp[0] = 0;
  dp[1] = D;
  std::cout << fix_point([&](auto dfs, int64_t cur) -> int64_t {
    if (auto it = dp.find(cur); it != dp.end()) {
      return it -> second;
    }
    int64_t res = inf;
    if (D <= inf / cur) {
      chmin(res, D * cur);
    }
    {
      int tmp = cur % 2;
      if (cur - tmp > 0) {
        chmin(res, A + dfs((cur - tmp) / 2) + D * tmp);
      }
      if (tmp != 0) {
        chmin(res, A + dfs((cur + 2 - tmp) / 2) + D * (2 - tmp));
      }
    }
    {
      int tmp = cur % 3;
      if (cur - tmp > 0) {
        chmin(res, B + dfs((cur - tmp) / 3) + D * tmp);
      }
      if (tmp != 0) {
        chmin(res, B + dfs((cur + 3 - tmp) / 3) + D * (3 - tmp));
      }
    }
    {
      int tmp = cur % 5;
      if (cur - tmp > 0) {
        chmin(res, C + dfs((cur - tmp) / 5) + D * tmp);
      }
      if (tmp != 0) {
        chmin(res, C + dfs((cur + 5 - tmp) / 5) + D * (5 - tmp));
      }
    }
    return dp[cur] = res;
  })(N) << '\n';
  return 0;
}

int main() {
  int testcase_count;
  scanf("%d", &testcase_count);
  while (testcase_count--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 4544
N = int(input())
S = input()

R = []
G = []
B = []
for i in range(N):
    if S[i] == "R":
        R.append(i)
    elif S[i] == "G":
        G.append(i)
    else:
        B.append(i)
        
ans = len(R) * len(G) * len(B)
for i in R:
    for j in G:
        if abs(j-i) % 2 == 1:
            k1 = min(j, i) - abs(j-i)
            k2 = max(j, i) + abs(j-i)
            if k1 >= 0:
                if S[k1] == "B":
                    ans -= 1
            if k2 <= N-1:
                if S[k2] == "B":
                    ans -= 1
        else:
            k1 = min(j, i) - abs(j-i)
            k2 = max(j, i) + abs(j-i)
            k3 = min(j, i) + abs(j-i)//2
            if k1 >= 0:
                if S[k1] == "B":
                    ans -= 1
            if k2 <= N-1:
                if S[k2] == "B":
                    ans -= 1
            if S[k3] == "B":
                ans -= 1
            
print(ans)

Measured memory_bytes: 69268
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }

    sort(L.begin(), L.end());
    const int max = L.back();
    L.pop_back();
    const int sum = accumulate(L.begin(), L.end(), 0);

    string str;
    if (sum > max)
        str = "Yes";
    else
        str = "No";
    cout << str << endl;

    return 0;
}

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

int l[200];

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

	for (int i = 0; i < 2*n; ++i)
		std::cin >> l[i];

	std::sort(l, l + 2*n);

	int ans = 0;
	for (int i = 0; i < n; ++i)
		ans += l[i * 2];

	std::cout << ans << std::endl;
}

Measured memory_bytes: 384
a, b = map(int, input().split())

if a <= 0 and b >= 0:
    print('Zero')
elif a > 0 and b > 0:
    print('Positive')
elif a < 0 and b < 0:
    if (b-a+1)%2 == 0:
        print('Positive')
    else:
        print('Negative')
    


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

int main(){
    int A,Be,C,D;
    string S;
    cin>>S;
    A = S.at(0) - '0';
    Be = S.at(1) - '0';
    C = S.at(2) - '0';
    D = S.at(3) - '0';

    for(unsigned int i=0;i<8;i++){
        bitset<4> B(i);
        int sum=A;
        queue<int> q;
        q.push(Be);
        q.push(C);
        q.push(D);
        for(int j=0;j<3;j++){
            if(B.test(j)){
                sum += q.front();
                q.pop(); 
            }else{
                sum-=q.front();
                q.pop();
            }
        }
        if(sum == 7){
            vector<char> a = {'1','2','3'};
            for(char& cha: a){
                if(B.test(cha-'1')){
                    cha = '+';
                }else{
                    cha = '-';
                }
            }
            cout<<A<<a.at(0)<<Be<<a.at(1)<<C<<a.at(2)<<D<<"=7"<<endl;
            return 0;

            
        }
    }
}

Measured memory_bytes: 256
N = int(input())
A = [0] + list(map(int, input().split())) + [0]


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


B = [0 for i in range(N+2)]
C = [0 for i in range(N+2)]
for i in range(1, N+1):
    B[i] = gcd(B[i-1], A[i])
for i in range(N, 0, -1):
    C[i] = gcd(C[i+1], A[i])
print(max(gcd(B[i-1], C[i+1]) for i in range(1, N+1)))

Measured memory_bytes: 66148
#include<stdio.h>
int i,j,c=0;
int search(int t,int n, int S[])
{
  int i=0;
  S[n] = t;
  while(S[i] != t){
    i++;
    if(i==n)
      return 0;
  }
  c++;
  //  printf("%d\n",c);
}
int main()
{
  int n,q;
  scanf("%d",&n);
  int S[n];
  for(i=0; i<n; i++)
    scanf("%d",&S[i]);
  scanf("%d",&q);
  int T[q];
  for(i=0; i<q; i++){
    scanf("%d",&T[i]);
    search(T[i],n,S);
  }
  printf("%d\n",c);
  return 0;
}



Measured memory_bytes: 2104
s = input()


def calc(formula):
    l = formula.split('+')
    ans = 0
    for n in l:
        ans += int(n)
    # print("ans: " + str(ans))
    return ans


def rec(s, cnt, l):
    # print(s)
    # print(cnt)
    # print(l)
    ret = 0
    if cnt < l:
        ret += rec(s, cnt+1, l)
        ret += rec(s[:cnt] + "+" + s[cnt:], cnt+2, l+1)
        return ret
    else:
        return calc(s)


print(rec(s, 1, len(s)))


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <stack>

typedef long long ll;

int main(int argc, char* argv[])
{
  ll X;
  std::cin >> X;

  ll ans = 0;
  for (int i = 1; i <= X; i++) {
    ll pos = i * (i+1) / 2;
    if (pos >= X) {
      ans = i;
      break;
    }
  }

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


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

int main(){
    string S;
    int N;
    cin >> S;
    N = (S[0]-'0')*100 + (S[1]-'0')*10 + (S[2]-'0');
    int min = abs(N-753);
    for(int i=1;i<S.size()-2;i++){
        if(min > abs((S[i]-'0')*100 + (S[i+1]-'0')*10 + (S[i+2]-'0')-753)){
            min = abs((S[i]-'0')*100 + (S[i+1]-'0')*10 + (S[i+2]-'0')-753);
        }
    }

    cout << min << endl;
}

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

int main() {
  long long a,v,b,w,t;
  cin >> a >> v >> b >> w >> t;

  long long k = abs(b-a);

  if (w>=v) {
    cout << "NO" << endl;
  }
  else {
    if ((v-w)*t >= k) {
      cout << "YES" << endl;
    }
    else cout << "NO" << endl;
  }
}  




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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    string s, t; cin >> s >> t;
    sort(all(s)); sort(all(t));
    reverse(all(t));
    if(s<t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
a_n = [0] * n
b_n = [0] * n
for i in range(n):
    a_n[i] = bisect.bisect_right(b, a[i])
for i in range(n):
    b_n[i] = n - bisect.bisect_right(c, b[i])
ans = 0
b_n_t = [0]
for i in range(n):
    b_n_t.append(b_n[i] + b_n_t[i])
for i in a_n:
    ans += b_n_t[-1] - b_n_t[i]
print(ans)

Measured memory_bytes: 28596
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,dp[100010][3],a[100010],b[100010],c[100010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	dp[1][0]=a[1];dp[1][1]=b[1];dp[1][2]=c[1];
	for(int i=2;i<=n;i++){
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
		dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
	}
	cout<<max(max(dp[n][0],dp[n][1]),dp[n][2])<<endl;
	return 0;
}

Measured memory_bytes: 4992
#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>;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    ll ans = 0;
    rep(i, n) {
        ll x = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        ll y = c.end() - upper_bound(c.begin(), c.end(), b[i]);
        ans += x * y;
    }
    cout << ans << endl;
    return 0;
}

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

ll arr[100007][3];
ll dp[100007][3];
bool vis[100007][3];
int n;

ll rec( int i, int prev  )
{
    if(i>=n)
        return 0;
    if(vis[i][prev])
        return dp[i][prev];

    ll ans= 0;
    for(int j=0;j<3;j++)
    {
        if(prev==j)
            continue;
        ans= max( ans, arr[i][j]+rec(i+1,j) );
    }

    vis[i][prev]= 1;

    return dp[i][prev]= ans;
}

int main()
{
    cin>>n;

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

    cout<< rec( 0, -1 ) <<endl;
}


Measured memory_bytes: 13056
"use strict";
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var v = {R:"B",B:"R"};

const rl=require("readline").createInterface(process.stdin,process.stdout);
const g=(function*(){
  const gets=()=>rl.once("line",s=>g.next(s));
  var ans = [];
  var n = yield gets();n = +n;
  var n2 = 2*n;
  var p = [];
  for(var i = 1; i <= n; i++)p[i-1] = i;
  console.log("?",p.join(" "));
  var s = yield gets();
  var l = 1, r = n+1,x;
  while(r-l>1){
    x = r+l+1>>1;
    for(var i = 0; i < n; i++)p[i] = x+i;
    console.log("?",p.join(" "));
    var t = yield gets();
    if(s[0] !== t[0])r = x;
    else l = x;
  }
  x = r;
  ans[x-2] = s[0];
  ans[x-2+n] = v[s[0]];
  var q = [];
  var set = new Set();
  for(var i = 0; i < n-1; i++){
    p[i] = (x+i) % (2*n);
    q[i] = (p[i]+n-1) % (2*n)+1;
    set.add(p[i]);
  }
  for(var i = 1; i <= 2*n; i++){
    if(ans[i-1])continue;
    if(set.has(i)){
      q[n-1] = i;
      console.log("?",q.join(" "));
      var t = yield gets();
      if(t[0] === "R")ans[i-1] = "R";
      else ans[i-1] = "B";
    }else{
      p[n-1] = i;
      console.log("?",p.join(" "));
      var t = yield gets();
      if(t[0] === "R")ans[i-1] = "R";
      else ans[i-1] = "B";
    }
  }
  console.log("!",ans.join(""));
})();
g.next();

Measured memory_bytes: 13332
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 105;
int n;
int a[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    a[i]--;
  }
  return true;
}

void solve() {
  for (int i = 0; i < n; i++) {
    if (a[i] > i) {
      printf("-1\n");
      return;
    }
  }
  vector<int> ans;
  while (n) {
    int i = n - 1;
    while (a[i] < i) {
      i--;
    }
    ans.push_back(i);
    for (int j = i + 1; j < n; j++) {
      a[j - 1] = a[j];
    }
    n--;
  }
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < sz(ans); i++) {
    printf("%d\n", ans[i] + 1);
  }
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n); for(ll i = 0; i < (ll)n; i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  ll n; cin >> n;
  vector<ll> a(n),b(n),c(n-1);
  rep(i, n)
    cin >> a.at(i);
  rep(i, n)
    cin >> b.at(i);
  rep(i, n-1)
    cin >> c.at(i);
  
  ll ans = 0;
  rep(i, n){
    ans += b.at(a.at(i)-1);
    if(i<n-1){
      if(a.at(i)+1 == a.at(i+1))
      ans += c.at(a.at(i)-1);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
typedef long long ll;
int main(){
    string S;
    cin>>S;
    int countA=0;
    int countB=0;
    rep(i,3){
        if(S[i]=='A'){
            countA++;
        }else{
            countB++;
        }
    }
    if(countA==3||countB==3){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
#define MOD 1000000007
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;}

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

    vector<ll> a(n);
    for(int i=0; i<n; i++) cin >> a[i];

    if (k == 1) {
        cout << 0 << endl;
        return 0;
    }

    ll offset = 0;
    unordered_map<ll, ll> mp;
    ll ans = 0;
    vector<ll> b(n);
    for (int i; i<n; i++) {
        b[i] = (1 - offset + k) % k;
        mp[b[i]]++;

        ans += mp[(a[i] - offset + k) % k];

        offset = (offset + 1 + a[i] * (k - 1)) % k;
        if (i - (k - 2) >= 0) 
            mp[b[i - (k - 2)]]--;
    }

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

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

using namespace std;

int main() {
	vector<int> furui(1000001, 0);
	furui[0] = furui[1] = 1;
	for (int i = 2; i*i <= 1000001; i++) {
		if (furui[i] == 0) {
			for (int j = 2; j <= 1000001/i; j++) {
				furui[i*j] = 1;
			}
		}
	}

	int a, d, n;
	while (cin >> a >> d >> n) {
		if (a == 0 && d == 0 && n == 0) {
			break;
		}
		while(n > 0) {
			if(furui[a] == 0) {
				n--;
			}
			a += d;
		}
		cout << a-d << endl;
	}
	return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> p(n);
  rep(i, q) {
      int a;
      cin >> a;
      --a;
      ++p[a];
  }
  rep(i, n) {
    if(p[i] >= q-k+1) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  return 0;
}
    

Measured memory_bytes: 3716
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
struct State { int x[19][15]; };
State S;
int dx[8] = { 1,1,1,0,-1,-1,-1,0 }, dy[8] = { -1,0,1,1,1,0,-1,-1 };
int solve(State p) {
	bool OK3 = false;
	for (int i = 0; i < 15; i++) { if (p.x[18][i] == 1 || p.x[17][i] == 1)OK3 = true; }
	if (OK3 == false)return 999999;
	int cx = 0, cy = 0;
	for (int i = 0; i < 285; i++) {
		if (p.x[i / 15][i % 15] == 2) { cx = i / 15; cy = i % 15; }
	}
	vector<int>vec;
	for (int i = 0; i < 8; i++) {
		int ex = cx + dx[i], ey = cy + dy[i];
		if (ex < 0 || ey < 0 || ex >= 19 || ey >= 15)continue;
		if (p.x[ex][ey] == 0)continue;
		vec.push_back(i);
	}
	if (vec.size() == 0)return 999999;
	int minx = 999999;
	for (int i = 0; i < 8; i++) {
		bool OK2 = false; for (int j = 0; j < vec.size(); j++) { if (vec[j] == i)OK2 = true; }
		if (OK2 == false)continue;
		State T = p;
		int ex = cx, ey = cy;
		bool flag = true;
		while (true) {
			ex += dx[i]; ey += dy[i];
			if (ex >= 19)break;
			if (ex < 0 || ey < 0 || ey >= 15) { flag = false; break; }
			if (T.x[ex][ey] == 0)break;
			T.x[ex][ey] = 0;
		}
		if (flag == false)continue;

		if (abs(ex - cx) <= 1 && abs(ey - cy) <= 1)continue;
		if (ex == 18 || ex == 19)minx = min(minx, 1);
		else {
			T.x[cx][cy] = 0; T.x[ex][ey] = 2;
			minx = min(minx, solve(T) + 1);
		}
	}
	return minx;
}
int main() {
	for (int i = 0; i < 19; i++) {
		for (int j = 0; j < 15; j++) {
			char p; cin >> p;
			if (p == 'O')S.x[i][j] = 2;
			if (p == 'X')S.x[i][j] = 1;
			if (p == '.')S.x[i][j] = 0;
		}
	}
	int R = solve(S); if (R >= 100000)R = -1;
	cout << R << endl;
	return 0;
}

Measured memory_bytes: 3204
n,k = gets.chomp.split(" ").map(&:to_i)
r,s,p = gets.chomp.split(" ").map(&:to_i)
t = gets.chomp

hash_item = {}
["r", "p", "s", "r"].each_cons(2){|a, b| hash_item[a] = b}
hash_point = {"r"=> r, "s"=> s, "p"=> p}

arr = []
result = 0
0.upto(t.length-1) do |i|
  c = t[i]
  tmp_item = hash_item[c]
  tmp_point = hash_point[tmp_item]

  prev_item = i < k ? nil : arr[i - k]
  if tmp_item != prev_item
    result += tmp_point
    arr << tmp_item
    next
  end

  next_c = t[i + k]
  next_item = hash_item[next_c]
  arr << (["r", "s", "p"] - [prev_item, next_item])[0]
end
puts result


Measured memory_bytes: 18528
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << (a % b != 0);
}


Measured memory_bytes: 256
let input = readLine()!.split(separator: " ").map { Int($0)! }
let H = input[0]
let W = input[1]
let K = input[2]

enum Square: Character {
    case white = "."
    case black = "#"
}

var c = [[Square]]()
var numberOfBlackSquares = 0
for _ in stride(from: 0, to: H, by: 1) {
    let row = Array(readLine()!).map { Square(rawValue: $0)! }
    c.append(row)
    numberOfBlackSquares += row.filter { $0 == .black }.count
}

// 後でなんかいい名前つける
let hoge = 1 << H
let woo = 1 << W

var dp = Array(repeating: Array(repeating: Optional<Int>.none, count: woo), count: hoge)
dp[0][0] = numberOfBlackSquares

for i in stride(from: 0, to: H, by: 1) {
    for state in stride(from: 0, to: hoge, by: 1) {
        guard state & (1 << i) == 0,
            let value = dp[state][0] else { continue }
        let nextState = state | (1 << i)
        dp[nextState][0] = value - c[i].filter { $0 == .black }.count
    }
}

for j in stride(from: 0, to: W, by: 1) {
    for rowState in stride(from: 0, to: hoge, by: 1) {
        for columnState in stride(from: 0, to: woo, by: 1) {
            guard columnState & (1 << j) == 0,
                let value = dp[rowState][columnState] else { continue }
            let nextColumnState = columnState | (1 << j)
          	// 名前募集中
            var numberOfTemp = 0
            for i in stride(from: 0, to: H, by: 1) {
                if rowState & (1 << i) == 0, c[i][j] == .black {
                    numberOfTemp += 1
                }
            }
            dp[rowState][nextColumnState] = value - numberOfTemp
        }
    }
}

let result = dp.reduce(0) { sum, row in
    sum + row.filter { $0 == K }.count
}
print(result)


Measured memory_bytes: 8408
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main() {
    let n:usize = read();
    let s:Vec<char>= read::<String>().chars().collect();
    let mut a: Vec<usize> = Vec::with_capacity(n); 
    let mut ans = 1;

    //各文字を数字に置き換える
    for (i,c) in s.iter().enumerate(){
        if c == &'R'{
            a.insert(i, 0);
        }
        if c == &'G'{
            a.insert(i, 1);
        }
        if c == &'B'{
            a.insert(i, 2);
        }
    }

    let mut count: Vec<i64> = vec![0,0,0];

    //各文字ごとの個数をカウント
    for i in 0..n {
        count[a[i]] += 1;
    }
    //全て異なる文字を選ぶ組み合わせ
    for i in 0..3 {
        ans *= count[i];
    }

    //全て異なる文字を選ぶ組み合わせ(全体) から 条件２に合致しないものを引くことで答えを求める

    // 1 <=i < j < k <= N 
    // i,jの組み合わせを全探索
    for j in 0..n {
        for i in 0..j {
            //kをj-i == k-jが成り立つように設定☆
            let k = j + ( j - i);
            if k < n {
                //println!("i{}j{}k{}",i,j,k);
                //a[i],a[j],a[k]のいずれかが同じ文字の場合、条件1に合致しないのでcontinueする
                if a[i] == a[j] { continue; }
                if a[i] == a[k] { continue; }
                if a[k] == a[j] { continue; }
                //println!("ans - 1");
                // j-i == k-j（3個の文字が等間隔）の場合、kの設定を受けて条件２に合致しないので引く
                ans -= 1;
            }
        }
    }

    println!("{}",ans);

}


Measured memory_bytes: 2156
#include<stdio.h>
int main(){
  int n,x,i,j,k,b=0,a[101]={0};
  while(1){
    scanf("%d %d",&n,&x);
    if(n==0&&x==0){
      break;
    }
    for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){
    if(j!=i){
      for(k=1;k<=n;k++){
        if(k!=i&&k!=j){
          if(i+j+k==x){
        a[b]++;
          }
        }
      }
    }
      }
    }
    b++;
  }
  for(i=0;i<b;i++){
    printf("%d\n",a[i]/6);
  }
}

Measured memory_bytes: 2592
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);



int main(){
	FAST_IO
	
	string s; cin >> s;
	
	auto check = [&](){
		if(s[0] == s[1] && s[1] == s[2]) return true;
		if(s[1] == s[2] && s[2] == s[3]) return true;
		return false;
	};
	
	if(check()) cout << "Yes\n";
	else cout << "No\n";		
	
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int sum;
	char ch[10000];
	while(1)
	{
		scanf("%s",ch);
		if(ch[0]=='0') break;
		sum=0;
		for(int i=0;i<strlen(ch);i++)
		{
			sum=sum+(ch[i]-'0');
		}
		printf("%d\n",sum);
	}
	
}

Measured memory_bytes: 1140
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.{NumericRange, Queue}
import scala.collection.mutable
import scala.io.StdIn.readLine

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val N = sc.nextLong
    if (N != -1) {
      solve2(sc, N = N, now = 0)
      solve(sc)
    }
  }

  val Data = Array[Long](
    Integer.parseInt("0111111", 2),
    Integer.parseInt("0000110", 2),
    Integer.parseInt("1011011", 2),
    Integer.parseInt("1001111", 2),
    Integer.parseInt("1100110", 2),
    Integer.parseInt("1101101", 2),
    Integer.parseInt("1111101", 2),
    Integer.parseInt("0100111", 2),
    Integer.parseInt("1111111", 2),
    Integer.parseInt("1101111", 2)
  )

  def solve2(sc: => Scanner, N: Long, now: Long): Unit = {
    if (N != 0) {
      val next = Data(sc.nextInt)
      println((now ^ next).toBinaryString.reverse.padTo(7, '0').reverse)
      solve2(sc, N - 1, next)
    }
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}


Measured memory_bytes: 45720
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D;
  int L,R;
  cin>>A>>B>>C>>D;
  L=A+B;
  R=C+D;
  if(L>R)cout<<"Left"<<endl;
  else if(L<R)cout<<"Right"<<endl;
  else if(L==R)cout<<"Balanced"<<endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int bubbleSort (int A[], int N) {

    int cnt = 0;

    bool flag = true;

    while (flag) {
        flag = false;
        for (int i = N - 1; i > 0; i--) {
            if (A[i] < A[i - 1]) {
                swap (A[i], A[i - 1]);
                flag = true;
                cnt++;
                // disp (A, N);
            }
        }
        // cout << endl;
    }

    return cnt;

}

void disp (int A[], int N) {

    for (int i = 0; i < N; i++) {
    
        if (i > 0) {
            cout << " ";
        }
        cout << A[i];
    
    }

    cout << endl;

}

int main () {

    int A[100], N;

    cin >> N;

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

    int cnt = bubbleSort (A, N);

    disp (A, N);

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).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;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    vector<int> a;
    int sum=0;
    rep(i,n){
        int t;cin>>t;
        sum+=t;
        a.emplace_back(t);
    }
    sort(a.rbegin(), a.rend());
    string ans = "Yes";
    rep(i,m){
        if(a[i]*(4*m)<sum) ans = "No";
    }
    cout<<ans<<endl;
}

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

#define P 1000003

long long int pow(long long int a, long long int n) {
	long long int ret = 1;
	while (n > 0) {
		if (n & 1) {
			ret = (ret * a) % P;
		}
		a = (a * a) % P;
		n >>= 1;
	}
	return ret;
}

long long int inv(long long int a) {
	return pow(a, P - 2);
}

int main(int argc, char const *argv[]) {
	long long int Q;
	long long int f[P];

	f[0] = 1;
	f[1] = 1;
	for (size_t i = 2; i < P; i++) {
		f[i] = (f[i - 1] * i) % P;
	}

	cin >> Q;
	for (size_t i = 0; i < Q; i++) {
		long long int x, d, n;
		cin >> x >> d >> n;

		if (x % P == 0) {
			cout << 0 << endl;
			continue;
		}

		if (d == 0) {
			cout << pow(x, n) << endl;
			continue;
		}

		long long int z = ((P - x) * inv(d)) % P;
		long long int start = P - z;
		long long int end = start + n - 1;

		if (z == 0 || end >= P) {
			cout << 0 << endl;
			continue;
		}

		long long int startmod = (pow(d, start - 1) * f[start - 1]) % P;
		long long int endmod = (pow(d, end) * f[end]) % P;
		long long int answer = (endmod * inv(startmod)) % P;

		cout << answer << endl;
	}
	return 0;
}


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

const int N = 0;
int n , m;
const int mod = 1e9 + 7;
long long ans1=0,ans2=0,ans;

int main()
{
	cin >> n >> m;
	
	vector < long long > v;
	
	v.clear();
	for(int i=0,x;i<n;i++)
	{
		scanf("%d",&x);
		v.push_back(x);
	}
	
	for(int i=v.size()-1;i>=0;i--)
	{
		ans1 += (i*v[i]) - ((v.size() - 1 - i)*v[i]);
		ans1 %= mod;
	}
		
	v.clear();
	for(int i=0,x;i<m;i++)
	{
		scanf("%d",&x);
		v.push_back(x);
	}
	
	for(int i=v.size()-1;i>=0;i--)
	{
		ans2 += (i*v[i]) - ((v.size() - 1 - i)*v[i]);
		ans2 %= mod;
	}
	
	ans = (ans1 * ans2) % mod;
	
	cout << ans;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int n,i,j;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	i=n*800;
	j=n/15*200;
	cout<<i-j;

	return 0;
}


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

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

  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    if(S.at(i)=='E') vec.at(i)=0;
    else if(S.at(i)=='W') vec.at(i)=1;
  }

  vector<int> E(N),W(N);
  for (int i = 0; i < N; i++) {
    if(i==0) E.at(i)=vec.at(i);
    else E.at(i)=E.at(i-1)+vec.at(i);
  }

  reverse(vec.begin(), vec.end());
  for (int i = 0; i < N; i++) {
    if(i==0) W.at(i)=1-vec.at(i);
    else W.at(i)=W.at(i-1)+(1-vec.at(i));
  }
  reverse(W.begin(), W.end());
  
  int count=N-1;
  int sum;
  for (int i = 0; i < N; i++) {
    if (i==0) sum=W.at(i+1);
    else if (i==N-1) sum=E.at(i-1);
    else sum=E.at(i-1)+W.at(i+1);
    count = min(count,sum);
  }
  cout << count << endl;
}

Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);

int main(){
	set<string> st;
	string tmp;
	ll n;
	cin>>n;
	fo(i,n) {
		cin>>tmp;
		st.insert(tmp);
	}
	cout<<sz(st)<<endl;
	

}




Measured memory_bytes: 19052
from heapq import heappush, heappop
import sys
input = sys.stdin.readline

INF = float('inf')
MOD = 10**9 + 7

def Dijkstra(adjList, vSt):
    numV = len(adjList)
    numUsed = 0
    costs = [INF] * numV
    costs[vSt] = 0
    nums = [0] * numV
    nums[vSt] = 1
    PQ = []
    heappush(PQ, (0, vSt))
    while PQ:
        cNow, vNow = heappop(PQ)
        if cNow > costs[vNow]: continue
        numUsed += 1
        if numUsed == numV: break
        for v2, wt in adjList[vNow]:
            c2 = cNow + wt
            if c2 < costs[v2]:
                costs[v2] = c2
                nums[v2] = nums[vNow]
                heappush(PQ, (c2, v2))
            elif c2 == costs[v2]:
                nums[v2] = (nums[v2]+nums[vNow]) % MOD
    return (costs, nums)

def solve():
    N, M = map(int, input().split())
    S, T = map(int, input().split())
    S, T = S-1, T-1
    edges = [tuple(map(int, input().split())) for _ in range(M)]
    adjL = [[] for _ in range(N)]
    for u, v, d in edges:
        adjL[u-1].append((v-1, d))
        adjL[v-1].append((u-1, d))

    costSs, numSs = Dijkstra(adjL, S)
    costTs, numTs = Dijkstra(adjL, T)
    minCost = costSs[T]

    ans = (numSs[T]**2) % MOD
    for v in range(N):
        if costSs[v] == costTs[v] == minCost/2:
            k = (numSs[v]*numTs[v]) % MOD
            ans -= (k**2) % MOD
            ans %= MOD
    for u, v, d in edges:
        u, v = u-1, v-1
        if costSs[u] > costSs[v]:
            u, v = v, u
        if costSs[u] < minCost/2 and costTs[v] < minCost/2 and costSs[u]+d+costTs[v] == minCost:
            k = (numSs[u]*numTs[v]) % MOD
            ans -= (k**2) % MOD
            ans %= MOD

    print(ans)

solve()


Measured memory_bytes: 105940
#include <stdio.h>


int main()
{
    int n, rk, c[4][13] = {0};
    char s;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf(" %c %d", &s, &rk);
        if (s == 'S')
        {
            c[0][rk - 1] = 1;
        }
        else if (s == 'H')
        {
            c[1][rk - 1] = 1;
        }
        else if (s == 'C')
        {
            c[2][rk - 1] = 1;
        }
        else if (s == 'D')
        {
            c[3][rk - 1] = 1;
        }
    }
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 13; j++)
        {
            if (c[i][j] == 0)
            {
            if (i == 0)
            {
                printf("S %d\n", j+1);
            }
            else if (i == 1)
            {
                printf("H %d\n", j+1);
            }
            
            else if (i == 2)
            {
                printf("C %d\n", j+1);
            }
            
            else if (i == 3)
            {
                printf("D %d\n", j+1);
            }
            
            }
        }
    }
  
    return 0;
}


Measured memory_bytes: 2052
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;

	
	public static void Main(string[] args)
	{
		int n = Console.ReadLine().ToInt();
		int wa = 0;
		for(int i = 1; i <= n; i++)
		{
			if(i%2==0)
				continue;
				
			int kazu = 0;
			for(int j = 1; j <= i; j++)
			{
				if(i % j == 0)
					kazu++;
			}
			if(kazu==8)wa++;
		}
		Console.WriteLine(wa);
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 13140
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

	int n;
	scanf("%d", &n);

	int A[n];
	for (int i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}
	int L[n];
	L[0] = A[0];
	int length = 1;
	for (int i = 1; i < n; ++i) {
		if (A[i] > L[length - 1]) {
			L[length++] = A[i];
		} else {
			int left = 0;
			int right = length;
			while (left < right) {
				int mid = (left + right) / 2;
				if (L[mid] >= A[i]) {
					right = mid;
				} else {
					left = mid + 1;
				}
			}
			L[right] = A[i];
		}
	}
	cout << length << endl;

	return 0;
}

Measured memory_bytes: 3912
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC

int main(){
    int n;cin>>n;
    vector<vector<lint>> vec(n,vector<lint> (3,0));
    for(int i=0;i<n;i++){
        cin>>vec[i][1]>>vec[i][2];
        vec[i][0]=vec[i][1]+vec[i][2];
    }
    sort(all(vec),greater<vector<lint>>());
    lint ans=0;
    for(int i=0;i<n;i++){
        if(i%2==0){
            ans+=vec[i][1];
        }
        else {
            ans-=vec[i][2];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 8676
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return x if y == 0 else gcd(y, x%y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N = I()
A = LI()

A.sort()

dp = [0] * (10**6+1)
for a in A:
    if dp[a] != 0:
        dp[a] = 2
        continue

    for i in range(a, 10**6+1, a):
        dp[i] += 1

ans = 0
for a in A:
    if dp[a] == 1:
        ans += 1

print(ans)


Measured memory_bytes: 126020