akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


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

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

ll vs[m+1][3];
rep(i,m){
	rep(j,2){
		vs[i][j]=0;
	}
}

if(n%2==0){
ll cnt=0;
ll a=1;
ll b=1+(n-2)/2;
ll fin=0;
for(int i=1;i<=1000000;i++){
	if(cnt==m){
		fin=1;
		break;}
		if(b<=a){break;}
	vs[cnt+1][1]=a;
	vs[cnt+1][2]=b;
	cnt++;
	a++;
	b--;
}
b=n;
a=b-(n-4)/2;
for(int i=1;i<=1000000;i++){
	if(fin) break;
	if(cnt==m) break;
	if(b<=a) break;
	vs[cnt+1][1]=a;
	vs[cnt+1][2]=b;
	cnt++;
	a++;
	b--;
}



}

else{
ll a,b;

a=n/2;
b=a+1;
for(ll i=1;i<=m;i++){
vs[i][1]=a;
vs[i][2]=b;
a--;
b++;

}


}

rep(i,m){

	cout<<vs[i][1]<<" "<<vs[i][2];
cout<<endl;
}



}


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

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

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

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

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        string S;
        cin >> S;
        Int K;
        cin >> K;
        bool same = true;
        for (auto e : S) {
            if (S[0] != e) same = false;
        }
        if (same) {
            Int ans = (S.size() * K) / 2;
            cout << ans << endl;
            return;
        }


        string beg, en, mid;
        beg += S[0];
        for (int i = 1; i < S.size(); ++i) {
            if (beg[0] == S[i]) {
//                beg.push_back(i);
                beg += S[i];
            } else {
                break;
            }
        }

//        en += S.back();
        for (int i = S.size() - 1; i >= 0; --i) {
            if (S.back() == S[i]) {
                en += S[i];
            } else {
                break;
            }
        }

        for (int i = beg.size(); i < S.size() - en.size(); ++i) {
            mid += S[i];
        }

        Int hasi = beg.size() / 2;
        Int ketu = en.size() / 2;
        Int hk = 0;
        if (beg[0] == en[0]) {
            hk = (beg.size() + en.size()) / 2 * (K - 1);
        } else {
            hk = (beg.size() / 2 + en.size() / 2) * (K - 1);
        }
        Int md = 0;
        vector<vector<char>> rl;
        for (auto e : mid) {
            if (rl.empty()) {
                rl.push_back(vector<char>());
                rl.back().push_back(e);
            } else {
                if (rl.back().back() == e) {
                    rl.back().push_back(e);
                } else {
                    rl.push_back(vector<char>());
                    rl.back().push_back(e);
                }
            }
        }
        for (auto e : rl) {
            md += e.size() / 2;
        }
        md *= K;

        Int ans = hasi + ketu + hk + md;
        cout << ans << endl;
    }
};


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

    Solve().solve();


    return 0;
}


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

using namespace std;

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

typedef long long ll;

const ll Inf = 1e15;
const double EPS = 1e-9;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<vector<ll> > a(n, vector<ll>(n));
    vector<vector<bool> > b(n, vector<bool>(n, true));
    rep (i, n) rep (j, n) cin >> a[i][j];
    rep (k, n) {
        rep (i, n) {
            rep (j, n) {
                if (a[i][j] > a[i][k] + a[k][j]) {
                    cout << -1 << endl;
                    return 0;
                }
                if (a[i][j] == a[i][k] + a[k][j]) {
                    if (i != k && k != j) b[i][j] = false;
                }
            }
        }
    }
    ll res = 0;
    rep (i, n) {
        FOR (j, i + 1, n) {
            if (b[i][j]) res += a[i][j];
        }
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 1024
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18



int main() {
	
	string s;
	vector<int> ls(26);
	while (getline(cin,s)) {
		
		for (auto c : s) {
			if (c <= 'Z'&&c >= 'A')ls[c - 'A']++;
			if (c <= 'z'&&c >= 'a')ls[c - 'a']++;
		}

	}

	for (int i = 0; i < 26; i++) {
		cout << char('a' + i) << " : " << ls[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3204
# ABC131 Anti-devision

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

def lcm(x, y):
    return (x * y) // gcd(x, y)

A, B, C, D = map(int, input().split())

ab_c = B // C - (A - 1) // C
ab_d = B // D - (A - 1) // D
cd_lcm = lcm(C, D)
ab_cd_lcm = B // cd_lcm - (A - 1) // cd_lcm

ans = B - (A - 1) - ab_c - ab_d + ab_cd_lcm

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int L;


signed main(){
    cin >> L;
    long double a = L/3.0;

    fcout << a*a*a << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
  int n,d;
  scanf("%d%d", &n, &d);
  int ans=n/((d*2)+1);
  if(n%((d*2)+1)!=0){
    ans++;
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve(){
}
int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int ans = 0;
    for(int i = 1; i < n; i++){
        int tmp = 0;
        vector<bool>an(26);
        vector<bool>bn(26);
        for (int j = 0; j < n; j++){
            if(j < i){
                an.at(s.at(j) - 'a') = true;
            }
            else{
                bn.at(s.at(j) - 'a') = true;
            }
        }
        for(int j = 0; j < 26; j++){
            if(an.at(j) && bn.at(j)){
                tmp++;
            }
        }
        ans = max(ans, tmp);
    }
    solve();
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int M = sc.nextInt();
   long tmp = 0;
   PriorityQueue<Long> pq = new PriorityQueue<> (Collections.reverseOrder());
   for(int i=0;i<N;i++) 
   {
     tmp = sc.nextLong();
     pq.add(tmp);
   }
   for(int i = 0;i<M;i++)
   {
     tmp = (long) pq.poll();
     tmp/=2;
     pq.add(tmp);
   }
   long ans =0;
   for(int i = 0;i<N;i++) ans += (long)pq.poll();
   
   System.out.println(ans);
 }
}

Measured memory_bytes: 53864
/**
 *    author:  tourist
 *    created: 26.11.2019 09:39:34       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long> dp(n);
  for (int i = 0; i < n; i++) {
    dp[i] = a[i];
  }
  vector<long long> new_dp(n);
  vector<int> st;
  for (int it = 1; it < k; it++) {
    new_dp[0] = (long long) -1e18;
    st.clear();
    int ptr = 0;
    for (int i = 0; i < n - 1; i++) {
      while (ptr < (int) st.size() && st[ptr] <= i - m) {
        ++ptr;
      }
      while (ptr < (int) st.size() && dp[st.back()] <= dp[i]) {
        st.pop_back();
      }
      st.push_back(i);
      new_dp[i + 1] = dp[st[ptr]] + (it + 1LL) * a[i + 1];
    }
    swap(dp, new_dp);
  }
  cout << *max_element(dp.begin(), dp.end()) << '\n';
  return 0;
}


Measured memory_bytes: 2812
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
using ll = long long;

int n,m,a,b,c,d,k;
string s,t;

int main() {
  cin >> a >> b >> c >> d >> k;
  cout << c*60+d-(a*60+b)-k << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
template <typename T, typename U>ostream &operator<<(ostream &out, const pair<T, U> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>void print(const ContainerType<ValueType, Args...> &c){for (const auto &v : c)cout << v << ' ';cout << '\n';} void print(){cout<<'\n';}
template <typename T, typename... Args>void print(T a, Args... args){cout << a << " ";print(args...);}
lli llipower(lli x, lli y, lli p = LLONG_MAX){lli res = 1;x = x % p;while (y > 0){if (y & 1)res = (res * x) % p;y = y >> 1;x = (x * x) % p;}return res;}

//8====================================D
int main(){
    int x;
    cin>>x;
    int kyu=9;
    for(int i=400;i<=1800;i+=200){
        if(x>=i) kyu--;
    }
    cout<<kyu<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
long long a[100004];
pair<long long,long long>b[100003];
bool cmp(pair<int,int>x,pair<int,int>y){
	if(x.first>y.first)return 1;
	else
	return 0;
}
int main(){
	long long n,m;
	cin>>n>>m;
	long long ans=0;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<m;i++)cin>>b[i].second>>b[i].first;
	sort(b,b+m,cmp);sort(a,a+n);
	int j=0;
	for(int i=0;i<n;i++)
		if(j!=m)
		{
			ans+=max(b[j].first,a[i]),
			b[j].second--;
			if(b[j].second==0)j++;
		}
		else
			ans+=a[i];
	cout<<ans;
}

Measured memory_bytes: 2688
class BinaryTree
  attr_accessor :root

  class Node
    attr_accessor :parent, :left, :right, :key

    def initialize(key)
      @key = key
      @parent = nil
      @left = nil
      @right = nil
    end
  end

  def initialize
    @root = nil
  end

  def insert(key)
    n = Node.new(key)
    y = nil
    x = @root

    while x != nil
      y = x
      x = if n.key < x.key
            x.left
          else
            x.right
          end
    end
    n.parent = y

    if y == nil
      @root = n
    elsif n.key < y.key
      y.left = n
    else
      y.right = n
    end
  end

  def find(key)
    n = @root
    while n != nil
      return n if n.key == key
      n = if key < n.key
        n.left
      else
        n.right
      end
    end
    return nil
  end

  def del(key)
    n = find(key)
    if n.left == nil || n.right == nil
      del_node = n
    else
      del_node = get_successor(n)
    end

    if del_node.left != nil
      x = del_node.left
    else
      x = del_node.right
    end

    if x
      x.parent = del_node.parent
    end

    if del_node.parent == nil
      @root = x
    elsif del_node == del_node.parent.left
      del_node.parent.left = x
    else
      del_node.parent.right = x
    end

    if n != del_node
      n.key = del_node.key
    end
  end

  def get_successor(n)
    if n.right
      return get_minimum(n.right)
    end

    y = n.parent
    while y != nil && n == y.right
      n = y
      y = y.parent
    end
    return y
  end

  def get_minimum(n)
    while n.left
      n = n.left
    end
    return n
  end

  def inorder(n)
    return unless n
    inorder(n.left)
    print " #{n.key}"
    inorder(n.right)
  end

  def preorder(n)
    return unless n
    print " #{n.key}"
    preorder(n.left)
    preorder(n.right)
  end

  def dump
    inorder(@root)
    print "\n"
    preorder(@root)
    print "\n"
  end
end

n = gets.to_i
bt = BinaryTree.new

n.times do |i|
  cmd, v = gets.split
  case cmd
  when "insert"
    bt.insert(v.to_i)
  when "find"
    puts bt.find(v.to_i) ? "yes" : "no"
  when "delete"
    bt.del(v.to_i)
  when "print"
    bt.dump
  end
end

Measured memory_bytes: 66416
from collections import Counter

N = int(input())

lst = []

for _ in range(N):
  S = input()
  S = sorted(S)
  S = ''.join(S)
  lst.append(S)

dic = Counter(lst)

rlt = 0
for k in dic:
  rlt += (dic[k]-1)*dic[k]//2
  
print(rlt)

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

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int er=0;
    int wr=0;
    for(int i=0;i<n;i++){
        if(s[i]=='E') er++;
        else wr++;
    }
    
    int el=0;
    int wl=0;
    int res=n;
    for(int i=0;i<n;i++){
        if(s[i]=='E') er--;
        else wr--;
        res=min(res,wl+er);
        if(s[i]=='E') el++;
        else wl++;
    }
    cout<<res<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using lli = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vlli = vector<lli>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define all(v) v.begin(), v.end()
#define debug(x) cout << x << endl
#define vout(v) rep(i, v.size()) cout << v[i] << " ";

int K, N;

void solve(vi A) {
	int ans = 2147483647;

	vi d(N);
	int total = 0;
	rep(i, N - 1) {
		int d_ = A[i + 1] - A[i];
		d[i] = min(d_, K - d_);
		total += d[i];
	}
	int d_ = abs(A[0] - A[N - 1]);
	d[N - 1] = min(d_, K - d_);
	total += d[N - 1];

	ans = min(ans, total - d[N - 1] - d[0] + min(d[N - 1], d[0]));
	rep(s, N - 2) { ans = min(ans, total - d[s - 1] - d[s + 1] + min(d[s - 1], d[s + 1])); }
	ans = min(ans, total - d[N - 2] - d[0] + min(d[N - 2], d[0]));
	cout << ans;
}

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

	vi A(N);
	rep(i, N) { cin >> A[i]; }

	solve(A);
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

#define ll long long

const ll mod = 1e9 + 7;

ll fact[200005] = { 1, };
ll fact_inv[200005] = { 1, };

ll get_inv(ll num)
{
	ll pow = mod - 2;
	ll ret = 1;
	ll mul = num;

	while (pow)
	{
		if (pow & 1) ret = (ret*mul) % mod;
		mul = (mul*mul) % mod;
		pow /= 2;
	}

	return ret;
}

int main()
{
	for (int i = 1; i <= 200000; ++i) fact[i] = (fact[i - 1] * i) % mod;
	fact_inv[200000] = get_inv(fact[200000]);
	for (int i = 199999; i >= 1; --i) fact_inv[i] = (fact_inv[i + 1] * (i + 1))%mod;

	ll N, M, K;

	scanf("%lld %lld %lld", &N, &M, &K);

	ll ans = 0LL;

	for (ll i = 1; i < N; ++i)
	{
			ll temp = (i*((M*M) % mod)) % mod;
			ll mul = (((fact[N*M - 2] * fact_inv[K - 2]) % mod)*fact_inv[N*M - K]) % mod;
			temp = (temp*mul) % mod;
			temp = (temp*(N - i)) % mod;
			ans = (ans + temp) % mod;
	}

	for (ll i = 1; i < M; ++i)
	{
		ll temp = (i*((N*N) % mod)) % mod;
		ll mul = (((fact[N*M - 2] * fact_inv[K - 2]) % mod)*fact_inv[N*M - K]) % mod;
		temp = (temp*mul) % mod;
		temp = (temp*(M - i)) % mod;
		ans = (ans + temp) % mod;
	}

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);++i)
#define pb(x) push_back(x)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
using namespace std;
typedef long long LL;
const int M = 1200000;
const int inf = 0x3f3f3f3f;
int n,m,k;
char s[M];
int a[100][100];
char g[111][111];
int dp[111][111];
bool vs[111][111];
void dfs(int u, int v, char c, int val) {
	if(vs[u][v]) return;
	//if(dp[u][v]<val) return;
	vs[u][v]=1;
	dp[u][v] = min(dp[u][v], val);
	if(g[u+1][v]==c)
		dfs(u+1, v, c, val);
	if(g[u][v+1]==c)
		dfs(u, v+1, c, val);
}
int main() {
	memset(dp,inf,sizeof(dp));
	dp[0][1] = dp[1][0] = 0;
	dp[1][1] = inf;
	cin >> n >> m;
	fo(i,1,n) cin >> (g[i]+1);
	memset(vs,0,sizeof(vs));
	dfs(1, 0, '.', 0);
	memset(vs,0,sizeof(vs));
	dfs(1, 0, '#', 1);
	fo(i,1,n)
		fo(j,1,m){
			memset(vs,0,sizeof(vs));
			dfs(i, j, '.', dp[i][j]);
			memset(vs,0,sizeof(vs));
			dfs(i, j, '#', dp[i][j]+1);
		}
	cout << dp[n][m] << endl;
	return 0;
}
/*
int main() {
	cin >> n >> s;
	fo(i,0,n-1) a[1][i+1] = s[i] - '0';
	fo(i, 2, n) {
		fo(j, 1, n+1-i) {
			a[i][j] = abs(a[i-1][j] - a[i-1][j+1]);
			cout << a[i][j] << ' ';
		}
		puts("");
	}
	return 0;
}
*/


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

vec eratosthenes(ll N){
  ll i;
  vec ch(N+1,1),p;
  ch[0]=ch[1]=0;
  rep(i,N+1){
    if(ch[i]){
      p.push_back(i);
      for(ll j=2;i*j<=N;j++){
        ch[i*j]=0;
      }
    }
  }
  return ch;
}
int main(){
  ll i,j,N;
  string ss;
  cin>>ss;
  N=ss.size();
  rep(i,N){
    if(i+1<N&&ss[i]==ss[i+1]){
      cout<<i+1<<" "<<i+2<<endl;
      return 0;
    }
    if(i+2<N&&ss[i]==ss[i+2]){
      cout<<i+1<<" "<<i+3<<endl;
      return 0;
    }
  }
  cout<<"-1 -1"<<endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<ll>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;


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

    ll ans = 1001001001001001;
    Rep(i, 1, sqrt(n)){
        ll t, a;
        if(n%i == 0){
            t = n/i;
            a = t + i;
            ans = min(ans, a);
        }
    }

    cout << ans -2 << endl;
}

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

#define FOR(i, a, b) for(int i = a; i < b; i ++)
#define FORS(i, a, b, c) for(int i = a; i < b; i += c)
#define FORN(i, a, b) for(int i = a; i <= b; i ++)
#define FORD(i, a, b) for(int i = a-1; i >= b; i --)
#define FORE(i, b) for(auto &i:b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i*i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a,n) a, a+n
#define SORT(a) sort(ALL(a))
#define SORTA(a, n) sort(ALLA(a, n))
#define REV(a) reverse(ALL(a))
#define REVA(a, n) reverse(ALLA(a, n))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl

#define PB  push_back
#define RB  pop_back
#define RF  pop_front
#define INS insert
#define F   first
#define S   second
#define UM  unordered_map
#define US  unordered_set
#define PQ  priority_queue

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pll;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef vector<vi> mi;
typedef vector<vd> md;
typedef vector<vll> mll;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pll> vpll;


int main(){
  IO; int N, K; cin >> N >> K;
  US<int> n;
  int d,t;
  while(K--){
    cin >> d;
    REP(i,d)cin>>t,n.INS(t);
  }
  cout << (N-n.size()) << endl;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cmath>

template <typename QvQ> inline QvQ Min(QvQ a,QvQ b){if(a<b) return a;return b;}
template <typename QvQ> inline QvQ Max(QvQ a,QvQ b){if(a>b) return a;return b;}

#define inf 2147483647
#define dinf 0x3f3f3f3f
#define llinf 0x7f7f7f7f7f7f7f7f

#define ll long long
#define rei register int
#define inv inline void
#define ull unsigned long long
#define il inline

#define bl putchar(' ')
#define ed putchar('\n')
#define test cout<<"this:" 

#define read2(a,b) read(a),read(b)
#define write2(a,b) write(a),bl,write(b)
#define read3(a,b,c) read(a),read(b),read(c)
#define write3(a,b,c) write(a),bl,write(b),bl,write(c)

template <typename QvQ>inv read(QvQ &x){
	x=0;int f=1;
	char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	x=x*f;
}
template <typename QvQ>inv write(QvQ x){
	if(x<0) x=-x,putchar('-');
	if(x>9) write(x/10);
	putchar(x%10+48);
}
using namespace std;
#define MAXN 100005
char s[MAXN];
int k;
int stk[MAXN],top;
int main()
{
	scanf("%s",s+1);
	read(k);
	int len=strlen(s+1);
	for(rei i=2;i<=len;++i) if(s[i]==s[i-1]) stk[++top]=i; stk[0]=-10;
	int base=0,ok=1;
	for(rei i=1;i<=top;++i)
	{
		++base;
		if(stk[i]==stk[i-1]+1)
		{
			if(ok) --base,ok=0;
			else ok=1;
		}
		else ok=1;
	}
	if(k==1)
	{
		write(base);
		return 0;
	}
	for(rei i=len+1;i<=len*3;++i) s[i]=s[i%len==0?len:i%len]; top=0;
	for(rei i=2;i<=len*3;++i) if(s[i]==s[i-1]) stk[++top]=i;
//	for(rei i=1;i<=len*3;++i) putchar(s[i]),bl;ed;
	int es=0;ok=1;
	for(rei i=1;i<=top;++i)
	{
		++es;
		if(stk[i]==stk[i-1]+1)
		{
			if(ok) --es,ok=0;
			else ok=1;
		}
		else ok=1;
	}
	int delta=es-base,tp=k-1; ll ans;
//	test,write(delta),bl,write(base),ed;
	if(tp%2==0)
	{
		ans=1ll*delta*(tp/2)+base;
		write(ans);
		return 0;
	}
	for(rei i=len+1;i<=len+len;++i) s[i]=s[i-len]; top=0;
	for(rei i=2;i<=len+len;++i) if(s[i]==s[i-1]) stk[++top]=i;
	es=0;ok=1;
	for(rei i=1;i<=top;++i)
	{
		++es;
		if(stk[i]==stk[i-1]+1)
		{
			if(ok) --es,ok=0;
			else ok=1;
		}
		else ok=1;
	}
	int delta2=es-base;
	if(tp==1)
	{
		write(es);
		return 0;
	}
	ans=1ll*delta*(tp/2)+base+delta2;
	write(ans);
	return 0;
}

Measured memory_bytes: 256
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def main():
    h, n = list(map(int, input().split()))
    a = list(map(int, input().split()))
    if sum(a) >= h:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 16556
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

//#include <set>
//#include <unordered_map>
//#include <stack>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

#define max_n 100

string S;
int N;

int main() {

	cin >> N >> S;
	int Sn[30000] = {-1};
	rep(i, N)Sn[i] = S.at(i) - '0';


	int ans = 0;

	bool icheck[10] = { false };

	for (int i = 0; i < N; i++) {

		bool fin = true;
		rep(q, 10) { if (!icheck[q])fin = false; }
		if (fin)break;

		if (icheck[Sn[i]])continue;
		icheck[Sn[i]] = true;

		bool jcheck[10] = { false };

		for (int j = i+1; j < N; j++) {

			bool jfin = true;
			rep(q, 10) { if (!jcheck[q])jfin = false; }
			if (jfin)break;

			if (jcheck[Sn[j]])continue;
			jcheck[Sn[j]] = true;

			bool kcheck[10] = { false };

			for (int k = j+1; k < N; k++) {
				bool kfin = true;
				rep(q, 10) { if (!kcheck[q])kfin = false; }
				if (kfin)break;

				if (kcheck[Sn[k]])continue;
				kcheck[Sn[k]] = true;
				ans++;
			}
		}
		
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<String> l = Arrays.asList(sc.nextLine().split(" "));
		int n = Integer.parseInt(l.get(0));
		int k = Integer.parseInt(l.get(1));
		String t = sc.nextLine();
		String changed = t.substring(k-1, k).toLowerCase();
		String answer = t.substring(0, k-1) + changed + t.substring(k, n);
		System.out.println(answer);
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;



int main()
{
    vll cost{0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    ll N, M; cin >> N >> M;
    vll A(M); rep(i, M) cin >> A[i];
    vll dp(N + 1, -inf);
    dp[0] = 0;
    for (ll i = 1; i <= N; i++) {
        for (ll a : A) {
            ll left = i - cost[a];
            if (left >= 0) dp[i] = max(dp[i], dp[left] + 1);
        }
    }
    //for (auto elem : dp) cout << elem << " "; cout << endl;

    sort(all(A), greater<ll>());
    //for (auto elem : A) cout << elem << " "; cout << endl;
    string ans = "";
    for (ll digit = dp[N]; digit > 0; digit--) {
        for (ll a : A) {
            if (N - cost[a] < 0) continue;
            if (dp[N] == dp[N - cost[a]] + 1) {
                N -= cost[a];
                ans += to_string(a);
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long int;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e10;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main() {
    ll n,m,a,b;
    P store[100005];
    cin >> n >> m;
    rep(i,n){
        cin >> a >> b;
        store[i] = P(a,b);
    }
    sort(store,store+n);
    ll cnt = 0,money = 0;
    rep(i,n){
        if (cnt+store[i].second < m) {
            money += store[i].first*store[i].second;
            cnt += store[i].second;
        }
        else{
            money += (m-cnt)*store[i].first;
            break;
        }
    }
    PRINT(money);
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

const int MAXN = 100005;

struct Edge
{
	int to;
	int nxt;
}edge[MAXN << 1];

int n,id,ans,MAX;
int u[MAXN];
int v[MAXN];
int a[MAXN];
int f[MAXN];
int deg[MAXN];
int sz[MAXN];
int first[MAXN];

char s[MAXN];

void addE(int u,int v)
{
	edge[++id] = (Edge){v,first[u]};
	first[u] = id;
}

void dfs(int u,int fa)
{
	sz[u] = a[u];
	for (int i = first[u];i;i = edge[i].nxt)
		if (edge[i].to != fa)
		{
			dfs(edge[i].to,u);
			sz[u] += sz[edge[i].to];
		}
}

void work(int u,int fa)
{
	int MX1 = 0,MX2 = 0;
	for (int i = first[u];i;i = edge[i].nxt)
		if (edge[i].to != fa)
		{
			work(edge[i].to,u);
			if (f[edge[i].to] >= MX1)
			{
				MX2 = MX1;
				MX1 = f[edge[i].to];
			}
			else if (f[edge[i].to] > MX2)
				MX2 = f[edge[i].to];
		}
	MAX = max(MAX,MX1 + MX2 + a[u]);
	f[u] = MX1 + a[u];
}

int main()
{
	scanf("%d",&n);
	for (int i = 1;i < n;i++)
	{
		scanf("%d%d",&u[i],&v[i]);
		addE(u[i],v[i]);
		addE(v[i],u[i]);
	}
	scanf("%s",s + 1);
	int st = 0;
	for (int i = 1;i <= n;i++)
	{
		a[i] = (s[i] == 'W');
		if (a[i])
			st = i;
	}
	if (!st)
	{
		puts("0");
		return 0;
	}
	dfs(st,0);
	id = 0;
	memset(first,0,sizeof(first));
	for (int i = 1;i < n;i++)
	{
		if (!sz[u[i]] || !sz[v[i]])
			continue;
		deg[u[i]]++;
		deg[v[i]]++;
		addE(u[i],v[i]);
		addE(v[i],u[i]);
		ans += 2;
	}
	if (!ans)
	{
		printf("%d\n",a[st]);
		return 0;
	}
	for (int i = 1;i <= n;i++)
	{
		if (deg[i] & 1)
			a[i] ^= 1;
		if (a[i])
			ans++;
	}
	work(st,0);
	ans -= MAX * 2;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 10880
N = int(input())
cps = {}
for i in range(1,N+1):
    city,point = input().split()
    point = int(point)
    if city in cps:
        cps[city].append((point,i))
    else:
        cps[city] = [(point,i)]
for k in sorted(cps.keys()):
    for v,idx in sorted(cps[k], reverse=True):
        print(idx)


Measured memory_bytes: 3060
import unittest


class TestD(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([[2, 4], [1, 9], [1, 8], [4, 9], [3, 12]]), 'Yes')

    def test_2(self):
        self.assertEqual(think([[334, 1000], [334, 1000], [334, 1000]]), 'No')

    def test_3(self):
        self.assertEqual(think([[384, 8895], [1725, 9791], [170, 1024], [4, 11105], [2, 6], [578, 1815], [702, 3352], [143, 5141], [1420, 6980], [24, 1602], [849, 999], [76, 7586], [85, 5570], [444, 4991], [719, 11090], [470, 10708], [1137, 4547], [455, 9003], [110, 9901], [15, 8578], [368, 3692], [104, 1286], [3, 4], [366, 12143], [7, 6649], [610, 2374], [152, 7324], [4, 7042], [292, 11386], [334, 5720]]), 'Yes')


def solve():
    list_of_a_and_b = read()
    result = think(list_of_a_and_b)
    write(result)


def read():
    n = read_int(1)[0]
    list_of_a_and_b = []
    for i in range(n):
        list_of_a_and_b.append(read_int(2))
    return list_of_a_and_b


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(data):
    data.sort(key=lambda x: (x[1], x[0]))
    current_time = 0
    for d in data:
        if current_time + d[0] > d[1]:
            return 'No'
        current_time += d[0]
    return 'Yes'


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 54232
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static Scanner sc = new Scanner(new InputStreamReader(System.in));

	public static void main (String[] args) throws Exception {
		while(true) {
			String str = br.readLine();
			if(str == null) break;
			StringTokenizer st = new StringTokenizer(str, ",");
			while(st.hasMoreTokens()) {
				int[] list = new int[11];
				list[0] = 0;
				for(int i=0; i<10; i++) {
					list[i+1] = list[i] + Integer.parseInt(st.nextToken());
				}
				int va = Integer.parseInt(st.nextToken());
				int vb = Integer.parseInt(st.nextToken());
				solve(list,va,vb);
			}
		}
	}
	
	public static void solve(int[] list, int va, int vb) {
		float d = (float)list[10];
		float a = (float)va;
		float b = (float)vb;
		float dest = d * a / (a+b);
		for(int i=0; i<10; i++) {
			if(dest<=list[i+1]) {
				System.out.println(i+1);
				return;
			}
		}
	}
}

Measured memory_bytes: 17320
import Control.Monad
import Text.Printf

main :: IO ()
main = do
    [a, b] <- getInts
    print $ if b `mod` a == 0 then a + b else b - a

getLines :: Int -> IO [String]
getLines n = replicateM n getLine

getLinesInt :: Int -> IO [Int]
getLinesInt n = fmap read <$> getLines n

getInts :: IO [Int]
getInts = map (read :: String -> Int) . words <$> getLine

getDoubles :: IO [Double]
getDoubles = map (read :: String -> Double) . words <$> getLine

Measured memory_bytes: 508
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val m = sc.nextInt()
  val h = (1..n).map {
    sc.nextInt()
  }
  val ab = (1..m).map {
    Pair(sc.nextInt(), sc.nextInt())
  }

  println(abc166c(n, m, h, ab))
}

private fun abc166c(n: Int, m: Int, h: List<Int>, ab: List<Pair<Int, Int>>): Int {
  val hArray = IntArray(n) { 0 }
  var i = 0
  for (hi in h) {
    hArray[i] = hi
    i++
  }
  val ans = BooleanArray(n) { true }

  for (abi in ab) {
    val a = abi.first - 1
    val b = abi.second - 1
    val ha = hArray[a]
    val hb = hArray[b]
    if (ha < hb) {
      ans[a] = false
    } 
    if (ha > hb) {
      ans[b] = false
    }
    if (ha == hb) {
      ans[a] = false
      ans[b] = false
    }
  }

  return ans.filter { it }.size
}


Measured memory_bytes: 68868
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[int(input())-1])

Measured memory_bytes: 38420
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        a: usize,
        b: usize,
    }

    if a==1 {
        if b==1 {
            println!("Draw");
        } else {
            println!("Alice");
        }
    } else {
        if b==1 {
            println!("Bob");
        } else {
            if a>b {
                println!("Alice");
            } else if a==b {
                println!("Draw");
            } else {
                println!("Bob");
            }
        }
    }

}


Measured memory_bytes: 2084
#include<iostream>

using namespace std;

int main(){
 int n;
 cin >> n;
 int a,b;
 a = n%100;
 b = (n-a)/100; 
 bool a_mm=false,a_yy;
 bool b_mm=false,b_yy;
 //ba

 if(a >= 1 && a<=12)
 {
     a_mm = true;
 }
 
 if(b >= 1 && b<=12)
 {
     b_mm = true;
 }
 if(a_mm){
     if(b_mm){
          cout << "AMBIGUOUS";
     }else{
          cout << "YYMM";
     }
 }else{
     if(b_mm){
         cout << "MMYY";
     }else{
         cout << "NA";
     }
 }
 
 //cout << i << endl;
}             

Measured memory_bytes: 256
def main():
    n, *a = map(int, open(0).read().split())
    p, q = min(a), max(a)

    if p == q:
        print(0)
        exit()

    x = []
    f, g = a.index(p) + 1, a.index(q) + 1
    if abs(p) > abs(q):
        for i in range(n):
            if a[i] > 0:
                x.append((f, i + 1))
        for i in range(n - 1):
            x.append((n - i, n - i - 1))

    else:
        for i in range(n):
            if a[i] < 0:
                x.append((g, i + 1))
        for i in range(n - 1):
            x.append((i + 1, i + 2))

    print(len(x))
    y = ['{} {}'.format(i[0], i[1]) for i in x]
    print('\n'.join(y))


if __name__ == '__main__':
    main()


Measured memory_bytes: 62236
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()

int n;
int p[1010], chk[10010];

void solve(int tc){
	scanf("%d", &n);
	for(int i=0;i<n;i++)scanf("%d", p+i);
	for(int i=0;i<=3;i++){
		for(int j=0;j<n-i;j++){
			int val = 0;
			for(int k=0;k<=i;k++){
				val = val * 10 + p[j+k];
			}
			chk[val] = 1;
		}
	}
	for(int i=0;i<5000;i++){
		if(!chk[i]){printf("%d\n", i);break;}
	}
}

int main(){
	int Tc = 1;// scanf("%d",&Tc);
	for(int i=1;i<=Tc;i++){
		solve(i);
	}
	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define INF (long)1e9
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	while(cin >> n >> m, n | m)
	{
		vector<P> vec;
		bool flag[m + 1];
		memset(flag, false, sizeof(flag));
		int a, b;
		for(int i = 0; i < n; i++)
		{
			cin >> a >> b;
			vec.push_back(P(b, a));
		}
		sort(vec.begin(), vec.end());
		reverse(vec.begin(), vec.end());
		int ans = 0;
		for(int i = 0; i < n; i++)
		{
			if(flag[vec[i].second] == false)
			{
				flag[vec[i].second] = true;
				ans += vec[i].first;
			}
		}
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 3140
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        List<List<Integer>> Array = new ArrayList<>();
        
        int n = sc.nextInt();
        
        for(int i=0;i<n;i++){
            List<Integer> array = new ArrayList<>();
            Array.add(array);
        }
        
        int q = sc.nextInt();
        
        for(int i=0;i<q;i++){
            int a = sc.nextInt();
            
            if(a == 0){
                int t= sc.nextInt();
                int x = sc.nextInt();
                Array.get(t).add(x);
            }else if(a == 1){
                int t = sc.nextInt();
                if(Array.get(t).size() != 0)
                System.out.println(Array.get(t).get(Array.get(t).size()-1));
            }else{
                int t = sc.nextInt();
                if(Array.get(t).size() != 0)
                Array.get(t).remove(Array.get(t).size()-1);
        	}
        }
    }
}


Measured memory_bytes: 167908
#include <iostream>
#include <string>

using namespace std;

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

    int n;
    cin >> n;

    int c[5] = {0};
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (s[0] == 'M') {
            c[0]++;
        } else if (s[0] == 'A') {
            c[1]++;
        } else if (s[0] == 'R') {
            c[2]++;
        } else if (s[0] == 'C') {
            c[3]++;
        } else if (s[0] == 'H') {
            c[4]++;
        }
    }

    long long ans = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            for (int k = j + 1; k < 5; k++) {
                ans += 1ll * c[i] * c[j] * c[k];
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
s=input()
q=int(input())
query=[input() for i in range(q)]
index=0
str_list=[[],[]]
for que in query:
  if len(que)==1:
    index=not index
  else:
    _,f,c=que.split()
    str_list[index^(int(f)-1)].append(c)
bf="".join(str_list[index][::-1])
af="".join(str_list[not index])
if index:
  s=s[::-1]
print(bf+s+af)

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
int A[1100];
signed main() {
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    int ans=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            ans=max(ans,abs(A[i]-A[j]));
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
///Author : - Code_X

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    string s;
    cin>>s;
    int l=0,w=0;
    for(ll i=0;i<s.length();i++)
    {
        if(s[i]=='o')
            w++;
        else
            l++;
    }
    if(l>7)
        cout<<"NO"<<'\n';
    else
        cout<<"YES"<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )

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

const int INF = 100000000;
const double PI=3.14159265358979323846;


int main () {
    int N;
    cin >> N; 
    
    vector<ll> A(N);
    vector<ll> B;

    rep(i,0,N) {
        cin >> A[i];
    }

    sort(A.begin(),A.end(),greater<int>());

    ll tmp = 0;
    rep(i,0,N) {
        if (tmp!=A[i]) {
            tmp = A[i];
        }
        else {
            B.push_back(tmp);
            tmp = 0;
        }
    }

    if (B.size()>=2) {
        ll ans = B[0]*B[1];
        cout << ans << endl;
    }
    else {
        cout << 0 << endl;

    }


}









Measured memory_bytes: 1660
import Control.Applicative
import Control.Monad
import Data.List
strToInt s = (read :: String -> Int) s

main :: IO ()
main = do
    s <- getLine
    t <- getLine
    let s' = sort s
    let t' = reverse $ sort t
    -- 出力
    putStrLn $ solve s' t'

solve :: String -> String -> String
solve xs [] = "No"
solve [] ys = "Yes"
solve (x:xs) (y:ys)
    | x == y = solve xs ys
    | x < y = "Yes"
    | otherwise = "No"


Measured memory_bytes: 508