akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

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


using ll = long long;

#define int ll

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
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; }


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, suff[4444], ans, suff2[4444], suff3[4444];
string s;
main() {
  file("threesum");
  ios;
  cin >> n >> s;
  for (int i = n - 1; ~i; --i) suff[i] = suff[i + 1] + (s[i] == 'B'), suff2[i] = suff2[i + 1] + (s[i] == 'R'),
    suff3[i] = suff3[i + 1] + (s[i] == 'G');
  for (int l = 0; l < n; ++l) {
    for (int r = l + 1; r < n; ++r) {
      if (s[l] != s[r] and s[l] != 'B' and s[r] != 'B') {
        int cnt = suff[r + 1];
        int dist = r - l;
        if (dist + r < n and s[dist + r] == 'B') --cnt;
        ans += cnt;
      } else {
        if (s[l] != s[r] and s[l] != 'R' and s[r] != 'R') {
          int cnt = suff2[r + 1];
          int dist = r - l;
          if (dist + r < n and s[dist + r] == 'R') --cnt;
          ans += cnt;
        } else {
          if (s[l] != s[r] and s[l] != 'G' and s[r] != 'G') {
            int cnt = suff3[r + 1];
            int dist = r - l;
            if (dist + r < n and s[dist + r] == 'G') --cnt;
            ans += cnt;
          }
        }
      }
    }
  }
  cout << ans;
  return 0;
}
/**

*/


Measured memory_bytes: 3760
local N, M = io.read("n", "n")
local cities = {}
local prefs = {}
for i=1,M do
     local p, y = io.read("n", "n")
     local c = {i, p, y, -1}
     if not prefs[p] then
         prefs[p] = {}
     end
     table.insert(prefs[p], c)
     table.insert(cities, c)
end
for k, v in pairs(prefs) do
    table.sort(v, function(x1, x2)
        return x1[3] < x2[3]
    end)
    for kk, vv in ipairs(v) do
        local ci = vv[1]
        cities[ci][4] = kk
    end
end

for i=1,M do
    local c = cities[i]
    local p = c[2]
    local x = c[4]
    print(string.format("%06d%06d", p, x))
end



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

int main()
{
  unsigned N, M, Q;
  std::cin >> N >> M >> Q;
  
  std::vector<unsigned> L(M), R(M);
  for (unsigned m = 0; m < M; ++m) {
    std::cin >> L[m] >> R[m];
  }
  
  std::vector< std::vector<unsigned> > cnt(N), sum(N);
  for (unsigned l = 0; l < N; ++l) {
    cnt[l] = std::vector<unsigned>(N, 0);
    sum[l] = std::vector<unsigned>(N + 1, 0);
  }
  
  for (unsigned m = 0; m < M; ++m) {
    ++cnt[L[m] - 1][R[m] - 1];
  }
  
  for (unsigned l = 0; l < N; ++l) {
    for (unsigned r = 0; r < N; ++r) {
      sum[l][r + 1] = cnt[l][r] + sum[l][r];
    }
  }
  
  for (unsigned i = 0; i < Q; ++i) {
    unsigned p, q, c = 0;
    std::cin >> p >> q;
    
    for (unsigned l = p - 1; l < q; ++l) {
      c += sum[l][q] - sum[l][p - 1];
    }
    
    std::cout << c << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int A,B,K;
    cin >> A >> B >> K;
    for(int i = 100;i >= 0;i--){
        if(A % i == 0 and B % i == 0)
            K--;
        if(K==0){
            cout << i << '\n';
            break;
        }
    }
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
    cin.tie(0);
  cout << setprecision(10);
 
  ll n, x; cin >> n >> x;
  vll a(n);
  REP(i, n) {
    cin >> a[i];
  }

  vll dp(n);
  ll ans = 0;
  
  REP(i, n) {
    dp[i] = a[i];
    ans += a[i];
  }

  FOR(i, 1, n) {
    REP(j, n) {
      dp[j] = min(dp[j], a[(j-i+n)%n]);
    }

    ll tmp = x * i;
    REP(j, n) {
      tmp += dp[j];
    }

    ans = min(tmp, ans);
  }

  cout << ans << endl;

  
  
}


Measured memory_bytes: 256
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    h,w=map(int,readline().split())
    a=[list(map(int,readline().split())) for _ in range(h)]

    i=0
    j=0
    n=0
    ans=[]
    while True:
        if i%2==0:
            if j<w-1:
                if a[i][j]%2==1:
                    n+=1
                    ans.append([i+1,j+1,i+1,j+2])
                    a[i][j+1]+=1
                j+=1
            elif j==w-1:
                if i<h-1:
                    if a[i][j]%2==1:
                        n+=1
                        ans.append([i+1,j+1,i+2,j+1])
                        a[i+1][j]+=1
                    i+=1
                else:
                    break
        else:
            if j>0:
                if a[i][j]%2==1:
                    n+=1
                    ans.append([i+1,j+1,i+1,j])
                    a[i][j-1]+=1
                j-=1
            elif j==0:
                if i<h-1:
                    if a[i][j]%2==1:
                        n+=1
                        ans.append([i+1,j+1,i+2,j+1])
                        a[i+1][j]+=1
                    i+=1
                else:
                    break

    print(n)
    for i in range(n):
        print(*ans[i])

if __name__=="__main__":
    main()

Measured memory_bytes: 30360
def main():
    n = input()
    m = len(n)
    ans = 0
    tmp = 0
    for i, v in enumerate(n):
        num = int(v)
        if num > 0:
            ans = max(ans, tmp + (num - 1) + (m-1-i)*9)
        tmp += num
    print(max(ans, tmp))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

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

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main(){
    int N,M;
    cin>>N>>M;
    UnionFind<int> uf(N);
    rep(i,M){
        int l,r,d;
        cin>>l>>r>>d;
        l--,r--;
        if(uf.issame(l,r)){
            int diff=uf.diff(l,r);
            if(diff!=d){
                cout<<"No"<<endl;
                return 0;
            }
        }
        else uf.merge(l,r,d);
    }

    cout<<"Yes"<<endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string s[100010],ab = "AB",bc = "BC",ac = "AC";
vector<char> v;
int main(){
    int i,n,a,b,c;
    cin >> n >> a >> b >> c;
    for(i=0;i<n;i++) cin >> s[i];
    s[n] = ab;
    for(i=0;i<n;i++){
        if(s[i]==ab){
            if(a<b) v.push_back('A'),a++,b--;
            else if(a>b) v.push_back('B'),a--,b++;
            else{
                if(s[i + 1]==ac) v.push_back('A'),a++,b--;
                else v.push_back('B'),b++,a--;
            }                
        }
        if(s[i]==bc){
            if(b<c) v.push_back('B'),b++,c--;
            else if(b>c) v.push_back('C'),b--,c++;
            else{
                if(s[i + 1]==ab) v.push_back('B'),b++,c--;
                else v.push_back('C'),b--,c++;
            }
        }
        if(s[i]==ac){
            if(a<c) v.push_back('A'),a++,c--;
            else if(a>c) v.push_back('C'),a--,c++;
            else{
                if(s[i + 1]==ab) v.push_back('A'),a++,c--;
                else v.push_back('C'),a--,c++;
            }
        }
        if(a<0 || b<0 || c<0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for(i=0;i<n;i++) cout << v[i] << endl;
}

Measured memory_bytes: 6900
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case(){
	ll n; cin >> n;
	int ans = 0;
	for(ll i = 2 ; i*i <= n ; i++){
		if(n%i==0){
			int cnt = 0;
			while(n%i==0){
				n/=i;
				cnt++;
			}
			for(int j = 1 ; j <= cnt ; j++){
				cnt-=j;
				ans++;
			}
		}
	}
	if(n != 1)
		ans++;
	cout<<ans<<"\n";
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    string s;
    cin >> s;

    while(s.size() < 15) s += "o";
    ll cnt = 0;
    REP(i, s.size()) {
        if(s[i] == 'o') cnt++;
    }
    if(cnt>=8) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - Logs
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int CNT = 100;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N];

/* subroutines */

int check(int n, int l) {
  ll c = 0;
  for (int i = 0; i < n; i++)
    c += (as[i] + l - 1) / l - 1;
  return c;
}

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  int maxa = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", as + i);
    if (maxa < as[i]) maxa = as[i];
  }

  int l0 = 0, l1 = maxa;
  while (l0 + 1 < l1) {
    int l = (l0 + l1) / 2;
    if (check(n, l) <= k) l1 = l;
    else l0 = l;
  }

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


Measured memory_bytes: 4000
#include <iostream>

void traceALDS12A(int arr[], int max) {
	for (int i = 0; i < max; ++i) {
		if (i)
			std::cout << " ";
		std::cout << arr[i];
	}
	std::cout << std::endl;
}
int main() {

	int N;
	std::cin >> N;

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

	int cnt = 0;

	for (int i = 0; i < N - 1; ++i) {
		for (int j = N - 1; j > i; --j) {
			if (arr[j] < arr[j - 1]) {
				std::swap(arr[j], arr[j - 1]);
				++cnt;
			}
		}
	}

	traceALDS12A(arr, N);
	std::cout << cnt << std::endl;

	return 0;
}

Measured memory_bytes: 3072
import numpy as np
import sys
a, b, h, m = map(int, input().split())
ang = abs((30 * h + .5 * m) % 360 - (6 * m) % 360)
ang *= np.pi / 180
print(np.sqrt(a**2 + b**2 - 2 * a * b * np.cos(ang)))
print('aaa', file=sys.stderr)

Measured memory_bytes: 27196
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;


public class Main {
	private	static	BufferedReader	br = null;
	private	static	MyConv			cv = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
		cv = new MyConv();
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
	// TODO Auto-generated method stub
		String	stdin = null;

		while ((stdin = parseStdin()) != null) {
			int		len = stdin.length();
			String	cnv = "";
			String	out = "";
			String	tmp = null;

			for(int l = 0; l < len; l++) {
				cnv += cv.get(stdin.substring(l, l+1));
			}

			len = cnv.length();
			for(int l = 1, m = 0; l <= len; l++) {
				tmp = cnv.substring(m, l);
				if (cv.containsKey(tmp)) {
					out += cv.get(tmp);
					m = l;
				}
			}

			System.out.println(out);
		}
	}

	private static String parseStdin() {
        String  stdin = null;
        
        try {
       		stdin = br.readLine();
        }
        catch (IOException e) {}
 
        return stdin;
	}
}

class MyConv extends HashMap<String, String>{
	public MyConv() {
		put("A", "00000");
		put("B", "00001");
		put("C", "00010");
		put("D", "00011");
		put("E", "00100");
		put("F", "00101");
		put("G", "00110");
		put("H", "00111");
		put("I", "01000");
		put("J", "01001");
		put("K", "01010");
		put("L", "01011");
		put("M", "01100");
		put("N", "01101");
		put("O", "01110");
		put("P", "01111");
		put("Q", "10000");
		put("R", "10001");
		put("S", "10010");
		put("T", "10011");
		put("U", "10100");
		put("V", "10101");
		put("W", "10110");
		put("X", "10111");
		put("Y", "11000");
		put("Z", "11001");
		put(" ", "11010");
		put(".", "11011");
		put(",", "11100");
		put("-", "11101");
		put("'", "11110");
		put("?", "11111");
		put("101", " ");
		put("000000", "'");
		put("000011", ",");
		put("10010001", "-");
		put("010001", ".");
		put("000001", "?");
		put("100101", "A");
		put("10011010", "B");
		put("0101", "C");
		put("0001", "D");
		put("110", "E");
		put("01001", "F");
		put("10011011", "G");
		put("010000", "H");
		put("0111", "I");
		put("10011000", "J");
		put("0110", "K");
		put("00100", "L");
		put("10011001", "M");
		put("10011110", "N");
		put("00101", "O");
		put("111", "P");
		put("10011111", "Q");
		put("1000", "R");
		put("00110", "S");
		put("00111", "T");
		put("10011100", "U");
		put("10011101", "V");
		put("000010", "W");
		put("10010010", "X");
		put("10010011", "Y");
		put("10010000", "Z");
	}
}

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

using namespace std;
int main(int argc, char **argv)
{
	int n,k,q,x;
    cin>>n>>k>>q;
    map<int,int> mp;
    vector<int> v(n,k);
    for(int i = 0 ; i < q;i++){
        cin>>x;
        mp[x]++;
    }
    
    for(int i = 0 ; i < n;i++){
        if(mp[i+1]){
            v[i] = k-(q-mp[i+1]);
        }
        else{
            v[i] = k-q;
        }
        v[i] > 0 ? cout<<"Yes"<<endl : cout<<"No"<<endl;
    }
	return 0;
}



Measured memory_bytes: 5760
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)

acum = []

# 総和を取る
for i in range(1, len(A)):
    acum.append(abs(A[i-1] - A[i]))

S = sum(acum)

ans = [0] * N
for skip_i in range(N):
    print(S - (acum[skip_i] + acum[skip_i+1]) + abs(A[skip_i] - A[skip_i+2]))


Measured memory_bytes: 14048
import sys
from collections import Counter

def ii(): return int(sys.stdin.readline())
def li(): return list(map(int, sys.stdin.readline().split()))

if __name__ == "__main__":
    n = ii()
    a = li()
    a = sorted(a)
    a_max = a[-1]
    sive = [True] * (a_max + 1)

    def sived(x):
        for non_ans in range(x, a_max+1, x):
            sive[non_ans] = False
    ans = 0
    for i in range(len(a)-1):
        if sive[a[i]]:
            sived(a[i])
            if a[i] != a[i+1]:
                ans += 1
    if sive[a_max]:
        ans += 1
    print(ans)


Measured memory_bytes: 33900
import math

def GCD(a,b,c):
    return math.gcd(math.gcd(a,b),c)

k = int(input())
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            ans += GCD(i,j,k)
print(ans)


Measured memory_bytes: 68212
n, m, k = map(int, input().split())
mod = 998244353

N = 10 ** 6


inv_t = [0]+[1]
for i in range(2, N):
    inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]


kai = [1, 1]
rev_kai = [1, inv_t[1]]
for i in range(2, N):
    kai.append(kai[-1] * i % mod)
    rev_kai.append(rev_kai[-1] * inv_t[i] % mod)


def cmb(n, r):
    return kai[n] * rev_kai[r] * rev_kai[n-r] % mod

base = m
ans = 0

for i in range(n-1):
    base = base * (m-1) % mod

for i in range(0, k+1):
    ans += base * cmb(n-1, n-1-i)
    ans %= mod
    base = base * inv_t[m-1] % mod

if m == 1 and k == n-1:
    print(1)
else:
    print(ans)


Measured memory_bytes: 167792
import java.util.*;

public class Main {
	public String HitBlow( int ans , int in ) {
		int hit = 0 , blow = 0;
		int[] a = new int[4] , b = new int[4];
		for ( int i = 0; i < 4; i++ ) {
			a[i] = ans % 10;
			ans /= 10;
			b[i] = in % 10;
			in /= 10;
		}
		for ( int i = 0; i < 4; i++ ) {
			if ( a[i] == b[i] ) hit++;
			else {
				for ( int j = 0; j < 4; j++ )
					if ( b[i] == a[j] ) blow++;
			}
		}
		return hit+" "+blow;
	}
	
	public static void main ( String[] args ) {
		Scanner sc = new Scanner(System.in);
		Main m = new Main();
		while ( true ) {
			int ans = sc.nextInt();
			int in = sc.nextInt();
			if ( ans == 0 && in == 0 ) break;
			System.out.println(m.HitBlow(ans, in));
		}
	}
}

Measured memory_bytes: 0
#include <stdio.h>
int main(){
  int S,h,m,s,x;
  scanf("%d",&S);
  h = S/3600;
  x = S%3600;
  m = x/60;
  s = x%60;
  
  printf("%d:%d:%d\n",h,m,s);
  return 0;

    }

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

struct edge {
    int to;
    int cost;
    int numOfTheaf;
};

struct info {
    int now;
    int sumOfCost;
    int sumOfTheaf;
    bool operator < (const info &o) const {
        return  sumOfTheaf > o.sumOfTheaf;
    }
};

int main() {
    int n, m, l;
    while (cin >> n >> m >> l, n) {
        vector <vector <edge> > G(n);
        rep (i, m) {
            int a, b, d, e;
            cin >> a >> b >> d >> e;
            a--; b--;
            G[a].push_back({b, d, e});
            G[b].push_back({a, d, e});
        }
        //       to, sumOfCost -> sumOfTheaf
        int dist[110][110] = {}; rep (i, 110) rep (j, 110) dist[i][j] = 1e9;
        bool used[110][110] = {};

        //info -> now, sumOfCost, sumOfTheaf
        priority_queue <info> que;
        que.push({0, 0, 0});

        dist[0][0] = 0;

        while (!que.empty()) {
            info tmp = que.top(); que.pop();
            if ( used[tmp.now][tmp.sumOfCost] ) continue;
            used[tmp.now][tmp.sumOfCost] = true;
            rep (i, G[tmp.now].size()) {
                //護衛を雇わない場合
                {
                    if ( dist[G[tmp.now][i].to][tmp.sumOfCost] > dist[tmp.now][tmp.sumOfCost] + G[tmp.now][i].numOfTheaf ) {
                        dist[G[tmp.now][i].to][tmp.sumOfCost] = dist[tmp.now][tmp.sumOfCost] + G[tmp.now][i].numOfTheaf;
                        que.push({G[tmp.now][i].to, tmp.sumOfCost, dist[G[tmp.now][i].to][tmp.sumOfCost]});
                    }
                }
                //護衛を雇う場合
                {
                //お金こえちゃだめ
                    if ( G[tmp.now][i].cost + tmp.sumOfCost > l ) continue;
                    if ( dist[G[tmp.now][i].to][tmp.sumOfCost + G[tmp.now][i].cost] > dist[tmp.now][tmp.sumOfCost] ) {
                        dist[G[tmp.now][i].to][tmp.sumOfCost + G[tmp.now][i].cost] = dist[tmp.now][tmp.sumOfCost];
                        que.push({G[tmp.now][i].to, tmp.sumOfCost + G[tmp.now][i].cost, tmp.sumOfTheaf});
                    }
                }
            }
        }
        int ans = 1e9;
        rep (i, l + 1) ans = min(ans, dist[n - 1][i]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3408
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <stack>
#include <list>
#include <deque>
using namespace std;
int n, m, i, j, k, t;
int main(){
	cin>>n>>m;
	t=100*n+1800*m;
	for(i=1;i<=m;i++){
		t*=2;
	}
	cout<<t;
	return 0;
}

Measured memory_bytes: 256
from itertools import combinations
import sys
n=int(input())
m=0
a=0
r=0
c=0
h=0
tmp=set()
for i in range(n):
    s=input()
    if s[0]=="M":
        m+=1
        tmp.add("m")
    elif s[0]=="A":
        a+=1
        tmp.add("a")
    elif s[0]=="R":
        r+=1
        tmp.add("r")
    elif s[0]=="C":
        c+=1
        tmp.add("c")
    elif s[0]=="H":
        h+=1
        tmp.add("h")
if len(tmp)<3:
    print(0)
    sys.exit()
tt=[]
for i in [m,a,r,c,h]:
    if i>0:
        tt.append(i)
ans=0
for i,j,k in combinations(tt,3):
    ans+=i*j*k
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <set>

using namespace std;

int main() {
    int n;
    string s;
    cin >> n;
    set<string> st;
    for (int i = 0; i < n; i++) {
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 19148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n;
    cin >> n;
    vector<ll>a(n);
    ll B=0;
    for(ll i=0;i<n;i++){
        cin >> a[i];
        B^=a[i];
    }
    for(ll i=0;i<n;i++){
        cout << (B^a[i]) << " ";
    }
}


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

int main() {
	int64_t N, L[100];
	L[0] = 2, L[1] = 1;
	cin >> N;
	for (int i = 2; i <= N; i++) {
		L[i] = L[i - 1] + L[i - 2];
	}
	cout << L[N] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repin(a, n)  \
    vector<ll> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repins(a, n)     \
    vector<string> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repind(a, n)     \
    vector<double> a(n); \
    rep(i, n) { cin >> a[i]; }
#define in(a) \
    ll a;     \
    cin >> a;
#define ins(a) \
    string a;  \
    cin >> a;
#define ind(a) \
    double a;  \
    cin >> a;
template <class T>
inline void out(T a) { cout << a << endl; }
inline void out(double a) { printf("%.10f\n", a); }
#define all(x)        (x).begin(), (x).end()
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define yes           out("Yes");
#define no            out("No");

int main() {
    long double a, b, c;
    cin >> a >> b >> c;
    if (a + 2 * sqrt(a * b) + b < c) {
        yes
    } else {
        no
    }
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    int al = 0;
    rep(i,n){
        al = al ^ a.at(i);
    }
    // cout << al << endl;
    rep(i,n){
        if(i>0) cout << " ";
        int ans = a.at(i) ^ al;
        cout << ans;
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;
const int MOD = 1e9 + 7;

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

  ll ans = 1;
  REP(i, 1, n){
    ans *= i;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> b(n);
    REP(i,n) cin>>a[i];
    REP(i,n) cin>>b[i];
  if(n==1){
        cout<<a[0]+b[0];
        return 0;
    }
    int d=0;
    int e=0;
    REP(i,n) {
        d+=b[i];
    }
        int f=0;
        int g;
    REP(i,n-1){
        e+=a[i];
        g=e+d;
        d-=b[i];
        f=max(f,g);
    }
    cout<<f;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		String S=sc.next();
		sc.close();
		char Scut[]=new char[4];
		boolean signal=false;
		for(int i=0;i<4;i++) {
			Scut[i]=S.charAt(i);
		}
		for(int j=0;j<3;j++) {
			if(Scut[j]==Scut[j+1]) {
				signal=true;
				break;
			}
		}
		if(signal) {
			System.out.println("Bad");
		}else {
			System.out.println("Good");
		}
	}
}

Measured memory_bytes: 23892
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
  int n;
  while(cin>>n,n){
    int cnt=0;
    while(n!=1){
      if(n%2){
	n*=3;
	n+=1;
      }else{
	n/=2;
      }
      cnt++;
    }
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,a,b,c,d = inpl()
s = input()
def chk(i):
    if s[i] == s[i+1] == '#':
        print('No')
        quit()
    return True
def cc(i):
    if s[i] == s[i+1] == s[i+2] == '.':
        return True
    return False

if c < d:
    for i in range(b-1,d-1):
        chk(i)
    for i in range(a-1,c-1):
        chk(i)
else:
    for i in range(b-2,d-1):
        if cc(i):
            break
    else:
        print('No')
        quit()
    for i in range(a-1,c-1):
        chk(i)
print('Yes')

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

int main() {
  string s;
  while (cin >> s) {
    if (s == "-") break;
    int T;
    cin >> T;
    while (T--) {
      int x;
      cin >> x;
      string a(s.begin(), s.begin() + x);
      string b(s.begin() + x, s.end());
      s = b + a;
    }
    cout << s << endl;
  }

  return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
typedef long long ll;

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

int main()
{
  int N, R;
  cin >> N >> R;

  if(N>9)
    cout << R << endl;
  else
    {
      cout << (10-N)*100+R << endl;
    }

  


  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



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

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

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

int main() {
  int n;
  cin >> n;
  vector<double> p(n);
  for(int i=0;i<n;i++) {
    cin >> p.at(i);
  }
  vector<vector<double>> dp(n+1,vector<double>(n+1,0));
  dp.at(0).at(0)=1;
  for(int i=0;i<n;i++) {
    for(int j=0;j<i+1;j++) {
      if(j<n) {
        dp.at(i+1).at(j+1)+=dp.at(i).at(j)*p.at(i);
      }
      dp.at(i+1).at(j)+=dp.at(i).at(j)*(1-p.at(i));
    }
  }
  double ans=0;
  for(int i=(n+1)/2;i<n+1;i++) {
    ans += dp.at(n).at(i);
  }
  printf("%.10f",ans);
}

Measured memory_bytes: 70656
#include<iostream>
#include<queue>
#include<vector>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int r;
    double ans=0;
    cin >> r;
    ans = 3.1415*2*r;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3772
#include<iostream>
#include<set>
using namespace std;
int main()
{
  int x,n; cin>>x>>n;
  
  
  set<int>s;
  for(int i = 0; i < n; i++)
  	{    int x; cin>>x; s.insert(x); }
  int i = 0;
  while(1)
  {
      x+=i;
      if(s.find(x) == s.end())
      	break;
      i++;
      x-=i;
      if(s.find(x) == s.end())
      	break;
      i++;
   }
  cout<<x;
  }


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[][] s = new char[3][];
		for (int i = 0; i < 3; i++) {
			s[i] = sc.next().toCharArray();
		}
		sc.close();

		int now = 0;
		int[] idx = new int[3];
		while (true) {
			if (idx[now] == s[now].length) {
				System.out.println((char) ('A' + now));
				return;
			}
			char next = s[now][idx[now]];
			idx[now]++;
			now = next - 'a';
		}
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
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;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 

vll dp(100100);

ll sum(ll n) {
ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    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;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}


 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n,k;
    ci(n>>k);
  st s;
    ci(s);
  vll A;
  ll count=1;
  FOR(i,1,n-1){
    if(s[i]!=s[i-1]){
      A.push_back(count);
      count=1;
    }
    else{
      count++;
    }
  }

  if(s[n-1]!=s[n-2]){
    A.push_back(count);
    A.push_back(1);
  }
  else{
    A.push_back(count+1);
  }

  ll a=A.sz;
  ll ans=0;
  FOR(i,0,a){
    ans+=A[i]-1;
  }
  
  if(k>=a/2){
    ans=n-1;
  }
  else{
    ans+=2*k;
  }
  co(ans)
  }

Measured memory_bytes: 2296
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import fractions
from functools import reduce
from operator import mul
import bisect
import sys
import logging
import heapq
import itertools

logging.basicConfig(level=logging.ERROR)

input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	n = int(input())
	a = list(map(int,input().split()))
	d = defaultdict(int)
	for i in a:
		d[i-1] += 1
		d[i]   += 1
		d[i+1] += 1
	ans = -1
	for i in range(-1,max(a)+3):
		if(d[i] > ans):
			ans = d[i]
	print(ans)

main()

Measured memory_bytes: 96744
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define int long long
#define vvectorl vector<vector<long long>>
#define vectorl vector<long long>
int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	int r = a % b;
	return gcd(b, r);
}
int squ(int x) {
	return x * x;
}
int di(vectorl x, vectorl y, int i, int j) {
	return squ(x[i] - x[j]) + squ(y[i] - y[j]);
}
int qmmin(int &a, int b) {
	if (a == -1) {
		a = b;
	}
	if (b!=-1){
		a= min(a, b);
	}
	return a;
}
signed main() {
	int n;
	cin >> n;
	vector<int> c(n, 0);
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	c[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++) {
		c[i] = min(c[i - 1] + abs(h[i] - h[i - 1]), c[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << c[n - 1] << endl;
}

Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

public class Main {
	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while (n != 0) {
			int gx = sc.nextInt();
			int gy = sc.nextInt();
			int p = sc.nextInt();
			int[][] dp = new int[gx + 1][gy + 1];
			int[][] st = new int[gx + 1][gy + 1]; // 通行可能:0 縦:1 横:-1 両方:2
			dp[0][0] = 1;
			for (int i = 0; i < p; i++) {
				int x1 = sc.nextInt();
				int y1 = sc.nextInt();
				int x2 = sc.nextInt();
				int y2 = sc.nextInt();
				int dis1 = x1 * x1 + y1 * y1;
				int dis2 = x2 * x2 + y2 * y2;
				if (dis1 > dis2) {
					if (st[x2][y2] == 0) {
						st[x2][y2] = x1 == x2 ? 1 : -1;
					} else {
						st[x2][y2] = 2;
					}
				} else {
					if (st[x1][y1] == 0) {
						st[x1][y1] = x1 == x2 ? 1 : -1;
					} else {
						st[x1][y1] = 2;
					}
				}
			}
			for (int i = 0; i <= gx; i++) {
				for (int j = 0; j <= gy; j++) {
					if (i - 1 >= 0 && st[i - 1][j] != -1 && st[i - 1][j] != 2) {
						dp[i][j] += dp[i - 1][j];
					}
					if (j - 1 >= 0 && st[i][j - 1] != 1 && st[i][j - 1] != 2) {
						dp[i][j] += dp[i][j - 1];
					}
				}
			}
			System.out.println(dp[gx][gy] == 0 ? "Miserable Hokusai!"
					: dp[gx][gy]);
			n--;
		}
	}
}

Measured memory_bytes: 12000
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
from pprint import pprint

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def Dijkstra(g, s):
    d = {}
    q = []
    done = set()
    for v in g.keys():
        d[v] = sys.maxsize
    d[s] = 0
    heapq.heappush(q, (d[s], s))

    while q:
        c, u = heapq.heappop(q)
        if u in done:
            continue
        done.add(u)
        for v in g[u]:
            alt = g[u][v] + d[u]
            if d[v] > alt:
                d[v] = alt
                heapq.heappush(q, (d[v], v))
    return d


@mt
def slv(N, XY, YS, XT, YT, XYR):
    p = [(XY, YS, 0, -1), (XT, YT, 0, -2)]
    for i, (x, y, r) in enumerate(XYR):
        p.append((x, y, r, i))

    def cost(p1, p2):
        c = math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) - p1[2] - p2[2]
        return max(0, c)

    g = defaultdict(dict)
    for i in range(N+2):
        for j in range(N+2):
            if i == j:
                continue
            d = cost(p[i], p[j])
            g[p[i][3]][p[j][3]] = d
            g[p[j][3]][p[i][3]] = d

    return Dijkstra(g, -1)[-2]


def main():
    XS, YS, XT, YT = read_int_n()
    N = read_int()
    XYR = [read_int_n() for _ in range(N)]
    print(slv(N, XS, YS, XT, YT, XYR))


if __name__ == '__main__':
    main()


Measured memory_bytes: 139736
import java.util.*;
 
public class Main { //クラス名はMain
    public static void main(String[] args) {
      //整数の入力
      Scanner sc = new Scanner(System.in);
      Integer N = Integer.parseInt(sc.next());
      
      String answer;
      int itinokurai = N % 10;
      if(itinokurai == 3){
        answer = "bon";
      }else if(itinokurai == 0 || itinokurai == 1 || itinokurai == 6 || itinokurai == 8){
        answer = "pon";
      }else{
        answer = "hon";
      }
      System.out.println(answer);
    }
}



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

int main() {
  int w[3]={0}, k[3]={0};
  for(int i=0; i<10; i++) {
    int data;
    cin >> data;
    if( w[0] <= data ) {
      w[2] = w[1];
      w[1] = w[0];
      w[0] = data;
    }
    else if( w[1] <= data ) {
      w[2] = w[1];
      w[1] = data;
    }
    else if( w[2] <= data ) {
      w[2] = data;
    }
  }

  for(int i=0; i<10; i++) {
    int data;
    cin >> data;
    if( k[0] <= data ) {
      k[1] = k[0];
      k[2] = k[1];
      k[0] = data;
    }
    else if( k[1] <= data ) {
      k[2] = k[1];
      k[1] = data;
    }
    else if( k[2] <= data ) {
      k[2] = data;
    }
  }

  cout << w[0]+w[1]+w[2] << " " << k[0]+k[1]+k[2] << endl;
}

Measured memory_bytes: 1164
#include <stdio.h>

int main(void)
{
	int array[9][9];
	int i,j;
	
	for(i=0;i<9;i++){
		for(j=0;j<9;j++){
			array[i][j]=(i+1)*(j+1);
			printf("%dx%d=%d\n",i+1,j+1,array[i][j]);
		}
	}
	
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main(){
    ll N;
    long double D;
    cin >> N >> D;
    vld X(N),Y(N);
    rep(i,N)
        cin >> X[i] >> Y[i];
    ll ans = 0;
    rep(i,N)
        if(X[i]*X[i] + Y[i]* Y[i] <= D*D)
            ans++;
    cout << ans << endl;

}

int main(int argc, char const *argv[])
{
    Main();
    return 0;
}

void yesno(bool state){
    if(state)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 9660
#!perl
use strict;
use warnings;
use utf8;
use feature qw/say/;

my $S = <STDIN>;
do {
    $S =~ s/(0|1)B//g;
    $S =~ s/^B//;
} while( $S =~ /(0|1)B/ );
$S =~ s/B//g;

print $S;

Measured memory_bytes: 768
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

const int MAX = 1e6 + 100;
long long fac[MAX], finv[MAX], inv[MAX];

void combInit() {
    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;
    }
}

long long comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int x, y;
    cin >> x >> y;

    if ((x + y) % 3 != 0) {
        std::cout << 0 << '\n';
        return 0;
    }
    int i = (2*x - y) / 3;
    int j = (2*y - x) / 3;
    if (i < 0 || j < 0) {
        std::cout << 0 << '\n';
        return 0;
    }

    combInit();
    std::cout << comb(i+j, i) << '\n';

    return 0;
}


Measured memory_bytes: 23680
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * Created by Aksenov239 on 12.03.2017.
 */
public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    BufferedReader br;
    StringTokenizer st;
    PrintWriter out;

    public String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public void solveA() throws IOException {
        int n = nextInt();
        int c = nextInt();
        int k = nextInt();

        int[] t = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = nextInt();
        }

        Arrays.sort(t);

        int ans = 0;
        for (int i = 0; i < n;) {
            int j = i;
            while (j < i + c && j < n && t[j] <= t[i] + k) {
                j++;
            }
            i = j;
            ans++;
        }
        out.println(ans);
    }

    public void solveB() throws IOException {
        int n = nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }

        Arrays.sort(a);

        int l = -1;
        int r = n;
        while (l < r - 1) {
            int m = (l + r) / 2;
            long size = a[m];
            for (int i = 0; i < m; i++) {
                size += a[i];
            }
            int i = m + 1;
            while (i < n && 2 * size >= a[i]) {
                size += a[i];
                i++;
            }
            if (i == n) {
                r = m;
            } else {
                l = m;
            }
        }
        out.println(n - r);
    }

    public void run() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);

            solveB();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 40488
from collections import deque

H, W = map(int, input().split())

sy, sx = map(int, input().split())
gy, gx = map(int, input().split())
sy -= 1
sx -= 1
gy -= 1
gx -= 1
Maze = [[_ for _ in input()] for __ in range(H)]
Q = deque()
Q.append((sy, sx, 0))
Cost = [[float('inf')] * W for _ in range(H)]
Cost[sy][sx] = 0
Move = []

for i in range(-2, 3):
    for j in range(-2, 3):
        if i == j == 0:
            continue
        Move.append((i, j))
Walk = ((-1, 0), (1, 0), (0, 1), (0, -1))
while Q:
    y, x, cost = Q.popleft()
    if Cost[y][x] >= Cost[gy][gx]:
        break
    if cost > Cost[y][x]:
        continue
    for wy, wx in Walk:
        ny = y + wy
        nx = x + wx
        if ny < 0 or ny >= H or nx < 0 or nx >= W or Maze[ny][nx] == '#':
            continue
        if Cost[ny][nx] > cost:
            Q.appendleft((ny, nx, cost))
            Cost[ny][nx] = Cost[y][x]

    for my, mx in Move:
        ny = y + my
        nx = x + mx
        if ny < 0 or ny >= H or nx < 0 or nx >= W or Maze[ny][nx] == '#':
            continue
        if Cost[ny][nx] <= Cost[y][x] + 1:
            continue
        Cost[ny][nx] = Cost[y][x] + 1
        Q.append((ny, nx, cost+1))

if Cost[gy][gx] == float('inf'):
    Cost[gy][gx] = -1
print(Cost[gy][gx])


Measured memory_bytes: 140340