akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>

using ll = long long;

using namespace std;

long long x = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= x;
	if (n % 2 == 1)t *= a;
	return t % x;
}

int main() {
	int n;
	ll k;
	cin >> n >> k;
	vector<ll>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll l = -1000000000000000000, r = 1000000000000000000;
	while (l + 1 < r) {
		ll x = (l + r) / 2;
		ll tot = 0;
		for (int i = 0; i < n; i++) {
			int l1 = -1, r1 = n;
			while (l1 + 1 < r1) {
				int c = (l1 + r1) / 2;
				if (a[i] < 0) {
					if (a[c] * a[i] < x)r1 = c; else l1 = c;
				}
				else {
					if (a[c] * a[i] < x)l1 = c; else r1 = c;
				}
			}
			if (a[i] < 0) {
				tot += n - r1;
			}
			else {
				tot += r1;
			}
			if (a[i] * a[i] < x)tot -= 1;
		}
		tot /= 2;
		if (tot < k) l = x; else r = x;
	}
	cout << l << endl;
	return 0;
}


Measured memory_bytes: 1792
attrs = Array.new
while line = $stdin.gets
  attrs << line.chomp.split
end
start_time = Time.now

K = attrs[0][0].to_i
sum = 0
for a in 1..K do
  for b in 1..K do
    tmp = a.gcd(b)
    for c in 1..K do
      sum += tmp.gcd(c)
    end
  end
end
puts sum

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <iomanip>
#include <cmath>
#include <set>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;

string s;
vector<string> ans;
void rec(int idx, vector<bool> state, string sum) {
    if(idx == s.size()) {
        ans.push_back(sum);
        return ;
    }
    char c = s[idx];
    if(state[c - 'a']) {
        rec(idx + 1, state, sum + c);
    }
    if(c + 1 <= 'z' && !state[c + 1 - 'a']) {
        state[c + 1 - 'a'] = true;
        rec(idx + 1, state, sum + string(1, (c + 1)));
    }
}

int main(){
    while(cin >> s && s != "#") {
        ans.clear();
        vector<bool> state(26, false);
        state[0] = true;
        rec(0, state, "");
        cout << ans.size() << endl;
        sort(ans.begin(), ans.end());
        if(ans.size() <= 10) {
            REP(i, ans.size()) cout << ans[i] << endl;
        } else {
            REP(i, 5) cout << ans[i] << endl;
            REP(i, 5) cout << ans[ ans.size() - 5 + i] << endl;
        }
    }
}

Measured memory_bytes: 2400
N,M=map(int, input().split())
class UnionFind():
  # 作りたい要素数nで初期化
  # 使用するインスタンス変数の初期化
  def __init__(self, n):
    self.n = n
    # root[x]<0ならそのノードが根かつその値が木の要素数
    # rootノードでその木の要素数を記録する
    self.root = [-1]*(n+1)
    # 木をくっつける時にアンバランスにならないように調整する
    self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
  def Find_Root(self, x):
    if(self.root[x] < 0):
      return x
    else:
    # ここで代入しておくことで、後の繰り返しを避ける
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]

    # 木の併合、入力は併合したい各ノード
  def Unite(self, x, y):
    # 入力ノードのrootノードを見つける
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    # すでに同じ木に属していた場合
    if (x == y):
      return 
      # 違う木に属していた場合rnkを見てくっつける方を決める
      #rnkが大きい方に結合
    elif (self.rnk[x] > self.rnk[y]):
      self.root[x] += self.root[y]
      self.root[y] = x

    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      # rnkが同じ（深さに差がない場合）は1増やす
      if(self.rnk[x] == self.rnk[y]):
        self.rnk[y] += 1

  # xとyが同じグループに属するか判断
  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)

  # ノードxが属する木のサイズを返す
  def Count(self, x):
    return -self.root[self.Find_Root(x)]


uni=UnionFind(N)
for i in range(M):
  x,y,z=map(int, input().split())
  uni.Unite(x-1,y-1)
L=[]
for i in range(N):
    a=uni.Find_Root(i)
    L.append(a)

print(len(set(L)))

Measured memory_bytes: 14760
import sys
sys.setrecursionlimit(500000)

import math

class Tree:
    def __init__(self, hp):
        self.hp = hp
        self.sons = []

    def split(self):
        return Tree(math.floor(self.hp/2)),Tree(math.floor(self.hp/2))
    

H = int(input())

num = 0
x = H
while x>1:
    x = math.floor(x / 2)
    num += 1


# ans = 1 + 2 + 4 + 8 + ..
ans = 0
for i in range(num+1):
    ans += 2**i

#ans += 2**num
print(ans)

Measured memory_bytes: 3064
s=list(input())
ans='AC'
if s[0]!='A':
    ans='WA'
if s[1]=='C':
    ans='WA'
t=s[2:-1]
if t.count('C')!=1:
    ans='WA'
u=list(set(s)-{'A','C'})
for i in range(len(u)):
    if u[i].isupper():
        ans='WA'
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define     ll          long long int
#define     ld          double
#define     REP(i,x,n)    for(ll i=x;i<n;i++)
#define     SZ(v)       (ll)v.size()
#define     endl        "\n"
#define     ff          first
#define     ss          second
#define     PQ_MIN      priority_queue <ll, vector<ll>, greater<ll> >
#define     PQ          priority_queue <int>
#define     pbds        tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define     setbit(x)   __builtin_popcount(x)
#define     prec(n)     fixed<<setprecision(n)
#define     pb(n)       push_back(n)
#define     mp(a,b)     make_pair(a,b)
#define     clr(n)      memset(n,0,sizeof(n))
#define     reset(n)    memset(n,-1,sizeof(n))
#define     ii          pair<ll,ll>
#define     vll         vector<ll>
#define     PI          3.1415926535897932384626433832795028841971693993751

using namespace std;
using namespace __gnu_pbds;
bool comp(pair<ll,ll> a,pair<ll,ll> b) {       }
const ll MOD=1e9+7;
void print(vector<vector<ll> >&v)
{
    ll n=v.size();
    ll m=v[0].size();
    cout<<"\n";
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<m;j++)
            cout<<v[i][j]<<" ";
        cout<<"\n";
    }
}
void print(vector<ll>&v)
{
    ll n=v.size();
    cout<<"\n";
    for(ll i=0;i<n;i++)
    {
            cout<<v[i]<<" ";
    }
        cout<<"\n";

}
void print(set<ll>&s)
{

cout<<endl;

set<ll>::iterator it;
for(it=s.begin();it!=s.end();it++)
    cout<<*it<<" ";
cout<<endl;
}
ll __lcm(ll a,ll b)
{
    return ((a*b)/__gcd(a,b));
}
ll power(ll a,ll p)
{
    ll res=1;
    while(p>0)
    {
        if(p&1){
            res=(res*a)%MOD;
            p--;
        }
            a=(a*a)%MOD;
            p/=2;
    }

    return res%MOD;
}
const ll INF=1e16;
const ll nxm=1e6+5;
ll n;
ll fact[nxm];
ll c(ll n,ll p)
{
    if(n==p)
        return 1;

    ll ans=fact[n];
    ans=(ans*power(fact[n-p],MOD-2))%MOD;
    ans=(ans*power(fact[p],MOD-2))%MOD;
    return ans;
}
void solve(){
cin>>n;

ll ans=0;
fact[0]=fact[1]=1;
REP(i,2,nxm)
fact[i]=(i*fact[i-1])%MOD;
for(ll i=1;i<n;i++)
{
    ll x=c(n,i);
    x=(x*((MOD+power(9,n-i)-power(8,n-i))%MOD))%MOD;
    ans=(ans+x)%MOD;
}
cout<<ans<<endl;
}
int main(){
//    freopen("timber_input", "r", stdin);
//    freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
//	cin>>t;
    REP(i,1,t+1)
    {
//    cout<<"Case #"<<i<<": ";
		solve();
    }
	return 0;
}
//  bitset<64>(x).to_ullong() // in my com  _ulong()
//  cout<<bitset<64>(ans).to_string().substr(64-m)<<endl;
/*

const int INF = 0x3f3f3f3f;


char s[100];

fgets(s,100,stdin);

stringstream stram(s);

string abc;

bool ok1=0,ok2=0;

while(stram>>abc)

ternary operator for(int i=0;i<23;i++) or while(r-l>eps)

struct P
{

    double logp;
    ll p;
    ll ind;

    	bool operator<(const P &p) const {
		if (abs(logp - p.logp) > 1e-7)
			return logp < p.logp;

		return ind < p.ind;
	} /// to use in set
};

*/


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

using namespace std;

/*
void printArray(int array[], int n) {
  for(int i=0; i<n; i++)
    cout<<"array["<<i<<"] = "<<array[i]<<endl;
  cout<<endl;
}
*/

int main() {
  int n, m;
  int taro[101], hanako[101];

  while(cin>>n>>m && n!=0 && m!=0) {
    int sumT = 0, sumH = 0;
    for(int i=0; i<n; i++) {
      cin>>taro[i];
      sumT += taro[i];
    }
    for(int i=0; i<m; i++) {
      cin>>hanako[i];
      sumH += hanako[i];
    }
    sort(taro, taro+n);
    sort(hanako, hanako+m);

    int swapT = 999, swapH = 999;
    for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) {
	int nowT = sumT-taro[i]+hanako[j];
	int nowH = sumH-hanako[j]+taro[i];
	if(nowT == nowH) {
	  if(taro[i]+hanako[j] < swapT+swapH) {
	    swapT = taro[i];
	    swapH = hanako[j];
	    j = m; // 高速化
	  }
	}
      }
    }
    if(swapT != 999) {
      cout<<swapT<<" "<<swapH<<endl;
    }
    else {
      cout<<"-1"<<endl;
    }
  }
}

Measured memory_bytes: 1180
// コンペ中に思ったとおりABC164_Dによく似ている。

#include<bits/stdc++.h>



#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
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 long long INF = 1LL<<60;

int lcm(int a,int b){
    //最小公倍数
    return a/__gcd(a,b) * b;
}



int n;
int main()
{
    cin>>n;
    vec<int> v(n);
    iota(v.begin(), v.end(), 1); //1からはじめるm要素の列
    
    map<int,int> mp;
    ll tmp=0;
    ll ans=0;
    rep(i,n){
        cin>>tmp;
        ans+=mp[i-tmp];
        mp[i+tmp]++;
    }
    


    cout<<ans<<endl;

    return 0;

}




Measured memory_bytes: 20972
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */


template<class Type>
Type solve(Type res = Type()){
    int N,M,s,t; cin >> N >> M >> s >> t;
    s--; t--;
    vector<vector<int>> G(N);
    for(int i = 0; i < M;i++){
        int u,v; cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    vector<int> dists(N,INF),distt(N,INF);
    
    auto dijkstra = [&](int from,vector<int>& dist){
        queue<ll> q;
        dist[from] = 0;
        q.push(from);
        while(q.size()){
            int u = q.front(); q.pop();
            for(auto v:G[u]){
                if(dist[v] > dist[u] + 1){
                    dist[v] = dist[u] + 1;
                    q.push(v);
                }
            }
        }
    };
    
    dijkstra(s,dists);
    dijkstra(t,distt);
    
    map<int,ll> L,R;
    for(int i = 0; i < N;i++){
        if(dists[i] != INF) L[dists[i]]++;
        if(distt[i] != INF) R[distt[i]]++;
    }
    int D = dists[t];
    for(int i = 0; i <= D;i++){
       //if(D-i-2 < 0) continue;
        res += L[i] * R[D-i-2];
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    //test();
    //solve<ll>();
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}




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

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<vector<ll>> a(n, vector<ll>(n));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            cin >> a.at(i).at(j);
        }
    }

    ll ans = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            ans += a.at(i).at(j);
        }
    }

    vector<vector<bool>> exist(n, vector<bool>(n, true));

    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            for(int k = j + 1; k < n; ++k){
                const ll dijk = a.at(i).at(j) + a.at(j).at(k);
                const ll dikj = a.at(i).at(k) + a.at(k).at(j);
                const ll djik = a.at(j).at(i) + a.at(i).at(k);
                if((dijk < a.at(i).at(k)) ||
                   (dikj < a.at(i).at(j)) ||
                   (djik < a.at(j).at(k))){
                    cout << -1 << endl;
                    return 0;
                }
                
                if(dijk == a.at(i).at(k) && exist.at(i).at(k)){
                    ans -= a.at(i).at(k);
                    exist.at(i).at(k) = false;
                }else if(dikj == a.at(i).at(j) && exist.at(i).at(j)){
                    ans -= a.at(i).at(j);
                    exist.at(i).at(j) = false;
                }else if(djik == a.at(j).at(k) && exist.at(j).at(k)){
                    ans -= a.at(j).at(k);
                    exist.at(j).at(k) = false;
                }
            }
        }
    }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111

	int dp[55][55][3100];

	void solve(){





		memset(dp,0,sizeof(dp));
		dp[0][0][0] =1;
		ini(n);
		ini(n1);
		FOR(i,0,n){
			ini(x);
			FOR(i1,0,n+1)FOR(i2,0,2555){dp[i+1][i1][i2] += dp[i][i1][i2];dp[i+1][i1+1][i2+x]+=dp[i][i1][i2];}
		}
		int rick =0;
		FOR(i,1,n+1){
			rick+=dp[n][i][n1*i];
		}
		out(rick);





















	}























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 73472
#include <bits/stdc++.h>
#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,r,l) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el
#define INF (1LL<<62)

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<long long,long long> pll;
typedef tuple<long double,int,int> tdii;
const double PI = atan(1)*4;
const int MAXN = 3e3 + 10;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int n;
double p[MAXN], q[MAXN], coins[MAXN], ans;

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout << setprecision(20)<< fixed;
    cin>>n;
    forn(i,n){
        cin>>p[i];
        q[i] = 1-p[i];
    }
    coins[0] = q[0];
    coins[1] = p[0];
    for1(i, n-1){
        coins[i+1] = coins[i] * p[i];
        fored(j, i, 1){
            coins[j] = coins[j]*q[i] + coins[j-1]*p[i];
        }
        coins[0] *= q[i];
    }
    fore(i, (n+1)/2, n){
        ans += coins[i];
    }
    cout<<ans<<el;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll A, B, C; cin >> A >> B >> C;
  ll K; cin >> K;
  ll count = 0;
  while (A>=B) { B*=2; count++; }
  while (B>=C) { C*=2; count++; }
  string result = count<=K ? "Yes" : "No";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));
#define pb push_back

//最大最小の入れ替え
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;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる
//時間を意識しろ
//コードテストちゃんとして
//画面とにらめっこするな書け
//WA出すたびにABCは五億円払え
//わからない問題はとばせ
//躊躇なくぐぐれ

//ここから
int main(){
    ll H,W,A,B;
    cin>>H>>W>>A>>B;
    rep(i,B){
        rep(j,A){
            cout<<1;
        }
        rep(j,W-A){
            cout<<0;
        }
        cout<<endl;
    }
    rep(i,H-B){
        rep(j,A){
            cout<<0;
        }
        rep(j,W-A){
            cout<<1;
        }
        cout<<endl;
    }
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int MOD = 1e9 + 7;

int add(int a, int b) {
	return (a + b) % MOD;
}

int mul(int a, int b) {
	return (a * b) % MOD;
}

int sub(int a, int b) {
	return (a - b + MOD) % MOD;
}

int binpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}

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

	int n, k;
	cin >> n >> k;
	vector<int> ans(k + 1);
	for (int i = k; i >= 1; i--) {
		int c = binpow(k / i, n);
		for (int j = 2 * i; j <= k; j += i) {
			c = sub(c, ans[j]);
		}
		ans[i] = c;
	}
	int res = 0;
	for (int i = 1; i <= k; i++) {
		res = add(res, mul(i, ans[i]));
	}
	cout << res << endl;
}


Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>/*toupperとかが入っている*/
#include<vector>/*可変長配列vectorのインクルード*/
using namespace std;/*標準名前空間を利用する。cinやcoutはこれによって利用可能になる*/

int P,Q,R;

int main(void) {
  cin >> P >> Q >> R;

  cout << min( Q+R, min(P+Q, P+R) ) << endl;
  return 0;
}

Measured memory_bytes: 256
char s[999],*v;k,u,p,c;main(){for(scanf("%s",s),v=s;*v;v++)*v-'K'||k++,*v-'U'||u++,*v-'P'||p++,*v-'C'||c++;k=u<k?u:k;k=p<k?p:k;printf("%d\n",c<k?c:k);exit(0);}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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


 
int main() {
    ll n, mn = INF, mx = 0;
    cin >> n;
    REP(i, n){
        ll a;
        cin >> a;
        mx = max(mx, a);
        mn = min(mn, a);
    }
    cout << mx - mn << '\n';
}

Measured memory_bytes: 256
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << n); bit++)
using namespace std;

template<class T>
void print(const T &value) {
    std::cout << value << std::endl;
}

void yesno(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; }

void YesNo(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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

ll INF = 10000000;
ll mod = 1000000007;//10^9+7
int dx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int dy[8] = {0, -1, 1, 0, -1, 1, -1, 1};
using Graph = vector<vector<int>>;//隣接リスト:G[i]にはiと隣接する頂点が入るよ。
using P = pair<int, int>;//BFSで利用。queueに入れる。
using lP = pair<ll, ll>;
using PP = pair<int, P>; //dijkstraで利用,priority_queueに入れる。
using p_queue = priority_queue<int, vector<int>, greater<int>>;//小さい順
//struct edge{int to, cost};
int max_N = 100000;

ll par[100000];
ll rnk[100000];
ll family[100000];

//n個のnodeで初期化する関数
void init(ll n) {
    REP(i, n) {
        par[i] = i;
        rnk[i] = 0;
        family[i] = 1;
    }
}

//木の根を求める。この際，親は根に更新される。
int find(ll x) {
    if (par[x] == x) { return x; }
    else { return par[x] = find(par[x]); }
}

//xとyの属する集合を融合
void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) { return; }

    if (rnk[x] < rnk[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rnk[x] == rnk[y]) { rnk[x]++; }
    }
}

//xとyが同じ集合に属するか判定
bool same(ll x, ll y) {
    return find(x) == find(y);
}


//番号ズレ注意！！
int main() {
    ll N, M;
    cin >> N >> M;
    ll A[M], B[M];
    REP(i, M) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }
    ll ans[100000];
    ans[M] = N * (N - 1) / 2;
    init(N);
    for (int i = M - 1; i >= 0; i--) {
        if (same(A[i], B[i])) {
            ans[i] = ans[i + 1];
            continue;
        }
        ll tmp = family[par[A[i]]] + family[par[B[i]]];
        ll com = family[par[A[i]]] * family[par[B[i]]];
        unite(A[i], B[i]);
        family[par[A[i]]] = tmp;
        family[par[B[i]]] = tmp;
        ans[i] = ans[i + 1] - com;
    }
    REP_1(i, M) {
        print(ans[i]);
    }
}

Measured memory_bytes: 6016
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <bitset>

using namespace std;
using ll=long long int;

int table[400][100010];

int main() {
    string s;
    cin >> s;
    int n = s.size();

    vector<int> ans(n, 0);
    int lastr = 0;
    for (int i = 1; i < n; ++i) {
        if (s[i] == 'R') {
            lastr = i;
        } else {
            int d = i - lastr;
            if (d % 2 == 0) {
                ans[lastr]++;
            } else {
                ans[lastr+1]++;
            }
        }
    }
    int lastl = n-1;
    for (int i = n-2; i >= 0; --i) {
        if (s[i] == 'L') {
            lastl = i;
        } else {
            int d = lastl - i;
            if (d % 2 == 0) {
                ans[lastl]++;
            } else {
                ans[lastl-1]++;
            }
        }
    }

    for (auto &e: ans) cout << e << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    static long[] V;
    static long[] dp;

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),k = sc.nextInt();
        V = new long[n + 1];
        dp = new long[n + 1];
        for (int i = 1; i <= n; i++) {
            V[i] = sc.nextLong();
            dp[i] = Integer.MAX_VALUE;
        }
        long ans = solve2(n,k);
        System.out.println(ans);
    }

    private static long solve2(int pos,int k) {
        if(dp[pos] != Integer.MAX_VALUE)
            return dp[pos];
        if(pos == 1)
            return 0;
        for (int i = 1; i <= k; i++) {
            if (pos - i >= 1)
                dp[pos] = Math.min(dp[pos], solve2(pos-i,k) + Math.abs(V[pos - i] - V[pos]));
            else
                break;
        }
        return dp[pos];
    }

    private static long solve(int n,int k) {
        dp[1] = 0;
        for (int j = 2; j <= n; j++) {
            for (int i = 1; i <= k; i++) {
                if (j-i >= 1)
                    dp[j] = Math.min(dp[j],dp[j-i] + Math.abs(V[j-i]-V[j]));
                else
                    break;
            }
        }
        return dp[n];
    }
}


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


using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}


int main(void){
    int N,K;
    cin>>N>>K;
    V<int> P(N);
    V<int> C(N);
    rep(i,N)cin>>P[i],--P[i];
    rep(i,N)cin>>C[i];
    ll ans = -LINF;

    rep(i,N){
        int v=i;
        int circle_cnt=0;
        ll circle_sum = 0;

        while(true){
            circle_cnt++;
            v=P[v];
            circle_sum+=C[v];
            if(v==i)break;
        }
        int cnt=0;
        ll path_sum = 0;
        
        while(true){
            cnt++;
            if(K<cnt)break;
            v=P[v];
            path_sum+=C[v];
            int num=(K-cnt)/circle_cnt;
            ll score=path_sum + num*max(0ll,circle_sum);
            chmax(ans,score);
            if(v==i)break;
        }

    }
    cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>

using namespace std;
using ll = long long;

// inf
const ll infl = 1LL << 60;
const int inf = 1 << 30;

int main() {
    ll N, A, B; cin >> N >> A >> B;
    if (N >= 2LL) {
        if (A <= B) {
            ll ans = (B * (N - 1LL) + A) - (A * (N - 1LL) + B) + 1LL;
            cout << ans << endl;
            return 0;
        }
    }
    cout << (A == B ? 1 : 0) << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
c = [0]*(n-1)
s = [0]*(n-1)
f = [0]*(n-1)

for i in range(n-1):
    c[i],s[i],f[i] = map(int,input().split())
for i in range(n):
    t = 0
    for j in range(i,n-1):
        if(t<s[j]):
            t = s[j]
        elif(t%f[j]):
            t += f[j]-(t%f[j])
        t += c[j]
    print(t)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    
    
    char a,b;
    cin>>a>>b;
    if(a=='H'){
        if(b=='H'){
            cout<<'H'<<endl;
        }
        else {
            cout<<'D'<<endl;
        }
    }
    else if(a=='D'){
        if(b=='H'){
            cout<<'D'<<endl;
        }
        else {
            cout<<'H'<<endl;
        }
    }

    
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] v = new int[n];
		for(int i =0; i < n; i++){
			int vn = sc.nextInt();
			v[i] = vn;
		}
		int sum = 0;
		for(int i = 0; i < n; i++){
			int cn = sc.nextInt();
			if(cn < v[i]){
				sum += (v[i] - cn);
			}
		}
		System.out.println(sum);
	}
}

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

using namespace std;

inline void read() {}
template <class S>
inline void read(S &arg) {
  cin >> arg;
}
template <class S>
inline void readA(S Lptr, S Rptr) {
  while (Lptr != Rptr) {
    read(*Lptr);
    Lptr++;
  }
}
template <class S, class... T>
inline void read(S &arg, T &... rest) {
  read(arg);
  read(rest...);
}

inline void write() {}
template <class S>
inline void write(S arg) {
  cout << arg;
}
template <class S>
inline void writeA(S Lptr, S Rptr) {
  if (Lptr != Rptr) {
    write(*Lptr);
    Lptr++;
  }
  while (Lptr != Rptr) {
    write('\n');
    write(*Lptr);
    Lptr++;
  }
}
template <class S, class... T>
inline void write(S arg, T... rest) {
  write(arg);
  write(' ');
  write(rest...);
}

#define int long long
#define rep(i, j, k) for (int i = j; i < (int)k; i++)
#define pb push_back
#define mt make_tuple
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

template <class T, class S>
inline bool smin(T &a, S b) {
  return (T)b < a ? a = b, 1 : 0;
}
template <class T, class S>
inline bool smax(T &a, S b) {
  return a < (T)b ? a = b, 1 : 0;
}

constexpr int MOD = 1e9 + 7;
constexpr int N = 1e6 + 10;

template <typename T>
inline T mod(T &v) {
  return v = (v % MOD + MOD) % MOD;
}
template <typename S, typename T>
inline S add(S &l, T r) {
  return mod(l += r);
}

ll po(ll v, ll u) {
  return u ? po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD : 1;
}

int n, k;
vi vec[N];
ll res[N];
vector<pair<int, pii>> st;
ll shiti[N];

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  memset(res, -1, sizeof(res));

  read(n, k);
  rep(i, 0, n) {
    int c, v;
    read(c, v);
    vec[c].pb(v);
  }

  rep(i, 1, k + 1) {
    sort(all(vec[i]), greater<int>());
    st.pb({-1 * (vec[i][0] + vec[i][1]), {0, i}});
    rep(j, 2, vec[i].size()) st.pb({-2 * vec[i][j], {j, i}});
  }
  sort(all(st));

  int sz = 0;
  ll sum = 0;
  ll last = 0;
  multiset<int> ms;

  for (int i = st.size() - 1; ~i; i--) {
    shiti[i] = shiti[i + 1];
    if (st[i].second.first == 0 && vec[st[i].second.second].size() > 2)
      smax(shiti[i], vec[st[i].second.second][2] - st[i].first);
  }

  rep(i, 0, st.size()) {
    smax(res[sz], sum);
    if (!ms.empty()) smax(res[sz + 1], sum + *ms.rbegin());
    if (shiti[i]) smax(res[sz + 3], sum + shiti[i]);
    if (last) smax(res[sz - 1], sum - last);
    if (st[i].second.first == 0) {
      sum -= st[i].first;
      sz += 2;
      if (vec[st[i].second.second].size() > 2)
        ms.insert(vec[st[i].second.second][2]);
    } else {
      sum -= st[i].first / 2;
      last = -st[i].first / 2;
      sz++;
      ms.erase(ms.find(vec[st[i].second.second][st[i].second.first]));
      if (vec[st[i].second.second].size() > st[i].second.first + 1)
        ms.insert(vec[st[i].second.second][st[i].second.first + 1]);
    }
  }
  smax(res[sz], sum);
  if (last) smax(res[sz - 1], sum - last);
  writeA(res + 1, res + n + 1);

  return 0;
}


Measured memory_bytes: 47212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()



int main(){
  int n, k, r, s, p;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  int ans = 0;
  rep(i, t.size()){
    if (t[i] == 'r') ans += p;
    else if (t[i] == 's') ans += r;
    else ans += s;
  }
  int cr = 1, cs = 1, cp = 1;
  for (int i = 0; i < k; i++) {
    int c = 1;
    char now = t[i];
    for (int j = i + k; j < n; j += k){
      if (t[j] == now){
        c++;
        if (j + k >= n){
          if (now == 'r') ans -= (c/2)*p;
          else if (now == 's') ans -= (c/2)*r;
          else ans -= (c/2)*s;
        }
      } else {
        if (now == 'r') ans -= (c/2)*p;
        else if (now == 's') ans -= (c/2)*r;
        else ans -= (c/2)*s;
        c = 1;
        now = t[j];
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;
using ll = long long int;
 
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,K,Q;
vector<ll> A;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> N >> K >> Q;
    A = fetch_vec<ll>(N);
}

int solve(){
    vector<ll> ans;
    ll maA = *max_element(A.begin(),A.end());
    for (int i = 0; i < N; i++)
    {
        ll y=A[i];
        // if(y==maA) continue;
        vector<ll> miny;
        int le=0;
        int ri=le;
        while(le<N){
            while(A[le]<y && le<N-1){le++;}
            ri=le;
            while(A[ri]>=y && ri<N){ri++;}
            // le~ri-1から小さいものをとる。
            if((ri-le)>=K){
                vector<ll> tmp;
                for(auto itr=(A.begin()+le);itr!=(A.begin()+ri);++itr){
                    tmp.push_back(*itr);
                }
                sort(tmp.begin(),tmp.end());
                for (int i = 0; i <= (ri-le-K); i++)
                {
                    miny.push_back(tmp[i]);
                }
                
            }
            le=ri;
            if(le>=N-1) break;
        }
        // ll X=*max_element(miny.begin(),miny.end());
        if(miny.size()>=Q){
            sort(miny.begin(),miny.end());
            // ll X=*min_element(miny.begin(),miny.end());
            ll X=miny[Q-1];
            DBG(miny)
            DBG(X)
            DBG(y)
            DBG(X-y)
            ans.push_back(X-y);
        }
    }
    ll ret = *min_element(ans.begin(),ans.end());
    cout << ret << endl;  
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
#include <set>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

ll n,k;
pair<ll,ll> p[100100];

int main(){
	cin>>n>>k;
	REP(i,n){
		ll a,b;
		cin>>a>>b;
		p[i]=pair<ll,ll>(a,b);
	}
	sort(p,p+n);
	ll ans=0;
	REP(i,n){
		if(ans+p[i].second>=k){
			cout<<p[i].first<<endl;
			return 0;
		}
		ans+=p[i].second;
	}
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
list = [input() for i in range(N)]

C0 = list.count("AC")
C1 = list.count("WA")
C2 = list.count("TLE")
C3  = list.count("RE")

print("AC","x",C0)
print("WA","x",C1)
print("TLE","x",C2)
print("RE","x",C3)

Measured memory_bytes: 16168
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <fstream>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;

int M,T,P,R;
int main(){
  int ms[10001];
  int ts[10001];
  int ps[10001];
  int js[10001];
  while(cin>>M>>T>>P>>R&&(M|T|P|R)){
    // waの数
    vector<pair<pii,int> > v(T);
    for(int i=0;i<T;i++)
      v[i]=make_pair(pii(0,0),i);
    int WAS[51][11]={};
    for(int i=0;i<R;i++){
      cin>>ms[i]>>ts[i]>>ps[i]>>js[i];
      ts[i]--;
      ps[i]--;
    }
    for(int i=0;i<R;i++){
      if(js[i]!=0){
        WAS[ts[i]][ps[i]]++;
      }
      else{
        v[ts[i]].first.first--;
        v[ts[i]].first.second+=WAS[ts[i]][ps[i]]*20;
        v[ts[i]].first.second+=ms[i];
      }
    }
    sort(v.begin(),v.end());
    map<pii,vector<int> > m;
    for(int i=0;i<(int)v.size();i++){
      m[v[i].first].push_back(v[i].second);
    }
    bool fst=true;
    for(map<pii,vector<int> >::iterator it=m.begin();
        it!=m.end();it++){
      if(fst)fst=false;
      else cout<<",";
      vector<int> v=it->second;
      sort(v.begin(),v.end(),greater<int>());
      for(int i=0;i<(int)v.size();i++){
        cout<<v[i]+1;
        if(i!=(int)v.size()-1)
          cout<<"=";
      }
    }
    cout<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1276
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  ll ans = 1, sub1 = 1, sub2 = 1;
  for (int i = 0; i < n; ++i) {
    ans = (ans * 10) % MOD;
    sub1 = (sub1 * 9) % MOD;
    sub2 = (sub2 * 8) % MOD;
  }
  ll sub = (sub1 + sub1) % MOD;
  sub = (sub + MOD - sub2) % MOD;
  ans = (ans + MOD - sub) % MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<stdlib.h>

int cmp( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
}
 
int main(){

  int n,size,i,j;
  
  (void) scanf("%d",&n);
  
  int a[n];
  
  for(i=0;i<n;i++)
  {
    scanf("%d",&a[i]);    
  }
  
  qsort(a, n, sizeof(int), cmp);
  
	for (i=0;i<n;i++)
    {
    	if (a[i]==a[i+1])
        {
         printf("NO");
          return 0;
        }
    
    
    }
  
  
  
  
  /*for (i=0;i<n;i++)  
  {
    for (j=i+1;j<n;j++)
    {
       printf("a[%d]=%d a[%d]=%d\n",i,a[i],j,a[j]);
      if (a[i]==a[j])
      {
        printf("NO");
        return 0;
      }
    }
        
  }*/
        
 printf("YES");      
 return 0; 
}

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

using namespace std;

int main(void) {
    long long n;
    vector <long long> a;
    cin >> n;
    for (long long i = 0; i < 3 * n; i++) {
        long long ai;
        cin >> ai;
        a.push_back(ai);
    }

    priority_queue <long long> left;
    long long sleft = 0;
    long long sl[300000];
    for (long long i = 0; i < 2 * n; i++) {
        left.push(-a[i]);
        sleft += a[i];
        if (left.size() > unsigned(n)) {
            sleft -= left.top() * (-1);
            left.pop();
        }
        sl[i] = sleft;
    }

    priority_queue <long long> right;
    long long sright = 0;
    long long sr[300000];
    for (long long i = 3 * n - 1; i >= n; i--) {
        right.push(a[i]);
        sright += a[i];
        if (right.size() > unsigned(n)) {
            sright -= right.top();
            right.pop();
        }
        sr[i] = sright;
    }

    long long res;
    res = -999999999999999;
    for (int i = n - 1; i < 2 * n; i++) {
        res = max(res, sl[i] - sr[i + 1]);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 11500
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pll = pair<long, long>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007
#define INFTY 1000000001

vector<vector<pll>> G(100000);
vb seen(100000,false);
vb finish(100000,false);
vb path(100000,false);

bool cir = false;

void dfs(long v){
  seen.at(v) = true;
  for(pll nP : G.at(v)){
    long nv = nP.first;
    
    if(finish.at(nv)) continue;
    if(seen.at(nv) && !finish.at(nv)){
      cir = true;
      return;
    }
    dfs(nv);
    if(cir) return;
  }
  finish.at(v) = true;
}

int main(){
  int n;
  cin >> n;
  vector<pll> ent(n);
  vector<long> b(n);
  vector<long> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  rep(i,n) cin >> b.at(i);
  rep(i,n){
    ent.at(i).second = a.at(i);
    ent.at(i).first = b.at(i);
  }
  sort(ent.begin(),ent.end());
  sort(b.begin(),b.end());
  sort(a.begin(),a.end());
  rep(i,n){
    if(a.at(i) > b.at(i)){
      cout << "No" << endl;
      return 0;
    }
  }
  vector<long> data(n);
  vector<long> risou(n);
  rep(i,n){
    long tmpa = ent.at(i).second;
    int iter = lower_bound(b.begin(),b.end(),tmpa) - b.begin();
    data.at(i) = iter;
    risou.at(i) = iter;
  }
  sort(risou.begin(),risou.end());
  long cnt = 0;
  rep(i,n) cnt += !(risou.at(i) == data.at(i));
  
  if(cnt < n){
    cout << "Yes" << endl;
    return 0;
  }
  set<long> st;
  rep(i,n){
    G.at(data.at(i)).push_back(pll(risou.at(i),i));
    st.insert(data.at(i));
  }
  dfs(data.at(0));
  rep(i,n){
    if(st.count(i) && !seen.at(i)){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

def main():
    ans = 1
    D = 10 ** 9 + 7
    N = int(input())
    T = list(map(int, input().split()))
    A = list(map(int, input().split()))
    L = len(T)
    ST, SA = [0] * L, [0] * L
    ST[0], SA[-1] = T[0], A[-1]
    if L > 1:
        if T[-1] != T[-2] : ST[-1] = T[-1]
        if A[0] != A[1] : SA[0] = A[0]
    for i in range(1, L-1):
        if T[i] == T[i-1] and A[i] == A[i+1]:
            ans = (ans * min(T[i], A[i])) % D
        else:
            if T[i] != T[i-1] : ST[i] = T[i]
            if A[i] != A[i+1] : SA[i] = A[i]
    for i in range(L):
        if ST[i] and SA[i] and ST[i] != SA[i]:
            ans = 0; break
        if A[i] < ST[i] or T[i] < SA[i]:
            ans = 0; break
    print(ans)
    
if __name__ == '__main__':
    main()

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int

using namespace __gnu_pbds;

typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;


#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
#define mod 1000000007
/* Precode Start Here *\


power of 2 less than or equal to N

ll largest_power(ll N)
{
    //changing all right side bits to 1.
    N = N (N>>1);
    N = N| (N>>2);
    N = N| (N>>4);
    N = N| (N>>8);


//as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
 2.
            return (N+1)>>1;

}


     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll a,b;
    cin>>a>>b;
    ll d=(100*a+7)/8;
    ll k=(100*b+9)/10;
    if(d>=k)
    {
        if((d*10)/100==b)
        {
            cout<<d<<endl;
        }
        else
        {
            cout<<-1<<endl;
        }
    }
    else
    {
        if((k*8)/100==a)
        {
            cout<<k<<endl;
        }
        else
        {
            cout<<-1<<endl;
        }
    }

    return 0;
}



Measured memory_bytes: 256
import math
A,B = map(int,input().split())
C = math.ceil(100*A/8)

if A % 2 == 0:
  D = math.floor(100*(A+1)/8)
else:
  D = math.floor(100*(A+1)/8)-1
  
for X in range(C,D+1):
  if B == math.floor(10*X/100):
    print(X)
    break
else:
  print(-1)

Measured memory_bytes: 3060