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

using namespace std;

using ll = long long;

int main() {
    ll X;
    cin >> X;
    for (ll i = 1;; i++) {
        ll s = X - i * i * i * i * i;
        for (ll j = 0; j <= i; j++) {
            ll t = j * j * j * j * j;
            if (t == s) {
                cout << i << " " << -j << endl;
                return 0;
            }
            if (t > s)
                break;
        }
        s = i * i * i * i * i - X;
        for (ll j = 0; j <= i; j++) {
            ll t = j * j * j * j * j;
            if (t == s) {
                cout << i << " " << j << endl;
                return 0;
            }
            if (t > s)
                break;
        }
    }
}


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

#define INF 100000000



int main(){
    int a,b,k;
    cin>>a>>b>>k;

    set<int> set;

    int bound1 = min(a+k,b+1);
    for(int i=a; i<bound1; ++i) set.insert(i);

    int bound2 = max(a-1,b-k);
    for(int i=b; i>bound2; --i) set.insert(i);

    auto itr = set.begin();
    while(itr != set.end()){
        cout<< *itr <<endl;
        ++itr;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print1(a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=55;
//i_am_noob
int n,ans=0;
string str;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n >> str;
	rep(sz(str)-2) if(str.substr(i,3)=="ABC") ans++;
	print1(ans);
	return 0;
}

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

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

int N;
int A[1000010];
int D[1000010];
int mem[1000010];
bool f;

int GCD(int a, int b)
{
    if(a % b == 0)return b;
    return GCD(b, a % b);
}

signed main()
{
    cin >> N;
    rep(i, N)cin >> A[i];

    for(int i = 2; i < 1000010; i++)
    {
        if(D[i] == 0)
        {
            for(int j = 1; j * i < 1000010; j++)D[i * j] = i;
        }
    }
    D[1] = 1;

    rep(i, N)
    {
        if(A[i] == 1)continue;
        int tmp = A[i];
        int now;
        while(D[tmp] != tmp)
        {
            now = D[tmp];
            if(mem[now] && mem[now] != i + 1)f = true;
            mem[now] = i + 1;
            tmp = tmp / D[tmp];
        }
        if(mem[tmp] && mem[tmp] != i + 1)f = true;
        mem[tmp] = i + 1;
    }

    if(f)
    {
        int gcd = GCD(A[0], A[1]);
        rep(i, N)gcd = GCD(gcd, A[i]);
        if(gcd == 1)
        {
            cout << "setwise coprime" << endl;
        }
        else cout << "not coprime" << endl;
        return 0;
    }

    cout << "pairwise coprime" << endl;

    return 0;
}


Measured memory_bytes: 26792
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/

import math
import statistics

def qsort(seq):
  if len(seq) < 1:
      return seq
  pivot = seq[0]
  left = []
  right = []
  for x in range(1, len(seq)):
    if seq[x] <= pivot:
        left.append(seq[x])
    else:
        right.append(seq[x])
  left = qsort(left)
  right = qsort(right)
  foo = [pivot]
  return (left + foo + right)

n  = int(input())
v  = list(int(i) for i in input().split())  
lastguzai = 0.00

for i in range(n):
  vs = sorted(v)
  if len(v) == 2:
    lastguzai = (v[0] + v[1]) / 2.00
    break
  v = vs
  lastguzai = (v[0] + v[1]) / 2.00
  del v[0:2]
  v.append(lastguzai)

print('{:.6f}'.format(lastguzai))


Measured memory_bytes: 5144
#include "bits/stdc++.h"
 
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;

vll k(1);
vll b(1);
ll solve(ll n,ll y){
    if(y>=k[n]) return b[n];
    if(y>k[n-1]+2) return b[n-1]+1+solve(n-1,y-k[n-1]-2);
    if(y==k[n-1]+2) return b[n-1]+1;
    if(y>1) return solve(n-1,y-1);
    return 0;
}
signed main(){
    llin(n);
    llin(x);
    k[0]=1;
    b[0]=1;
    FOR(i,1,n){
        k.pb(2*k[i-1]+3);
        b.pb(2*b[i-1]+1);
    }
    sal(solve(n,x));
}


Measured memory_bytes: 256
def sol():
    x, y = map(int, input().split())
    for i in range(x+1):
        for j in range(x+1):
            if (i+j) == x and 4*i + 2*j == y:
                print("Yes")
                return
    print("No")

if __name__ == "__main__":
    sol()


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

int go(vector<int> &arr, int i, vector<int> &dp){

  if(i >= arr.size()-1)
    return 0;

  if(dp[i] != -1)
    return dp[i];
  
  int &ans = dp[i];
  if(i == arr.size()-2)
    ans =  abs(arr[i+1]-arr[i]) + go(arr, i+1, dp);
  else
    ans = min(abs(arr[i+1] - arr[i]) + go(arr, i+1, dp), abs(arr[i+2] - arr[i]) + go(arr, i+2, dp));

  return ans;
}


int main(){

  int n;
  cin >> n;

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

  vector<int> dp(arr.size(), -1);
  cout << go(arr, 0, dp) << endl;

  return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"

typedef long lint;
typedef pair<lint, lint> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    
    lint K; cin >> K;

    set<string> subs;
    
    FOR(k,1,K+1) {
      REP(i, s.length()) {
        subs.insert(s.substr(i,k));
      }
    }

    vector<string> list(subs.begin(), subs.end());
    SORT(list);

    PRINT(list[K-1]);

    //    EACHPRINT(list, string);

  
    
    return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
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; }

struct Edge {
    ll to, idx;
    Edge () {}
    Edge (int to, int idx) : to(to), idx(idx) {}
};

vector<vector<Edge>> G(100005);

ll N, M;
ll D[100005];
ll U[200005], V[200005];

ll ans[200005];

bool flag[100005] = {};

int main() {
    cin >> N >> M;
    string color(N, '.');
    for (int i = 0; i < N; i++) {
        cin >> D[i];
    }
    char inv[256];
    inv['B'] = 'W';
    inv['W'] = 'B';
    priority_queue<Pl, vector<Pl>, greater<Pl>> que;
    fill_n(ans, 200005, 1000000000);
    for (int i = 0; i < M; i++) {
        cin >> U[i] >> V[i]; --V[i], --U[i];
        if (D[U[i]] == D[V[i]] && (!flag[U[i]] || !flag[V[i]]) ) {
            if (color[U[i]] == '.' && color[V[i]] == '.') { 
                color[U[i]] = 'B';
                color[V[i]] = 'W';
            } else if (color[U[i]] != '.') color[V[i]] = inv[color[U[i]]];
            else if (color[V[i]] != '.') color[U[i]] = inv[color[V[i]]]; 
            ans[i] = D[U[i]];
            flag[U[i]] = true;
            flag[V[i]] = true;
            que.emplace(D[U[i]], U[i]);
            que.emplace(D[U[i]], V[i]);
        } else {
            G[U[i]].emplace_back(V[i], i);
            G[V[i]].emplace_back(U[i], i);
        }
    }


    while (!que.empty()) {
        auto d = que.top(); que.pop();
        ll v = d.second;
        for (auto &u : G[v]) {
            if (flag[u.to] == false && D[u.to] > D[v]) {
                ans[u.idx] = D[u.to] - D[v];
                flag[u.to] = true;
                color[u.to] = color[v];
                que.emplace(D[u.to], u.to);
            }
        }
    }
    int cnt = count(flag, flag + N, true); 
    if (cnt < N) {
        cout << -1 << endl;
        return (0);
    } 

    cout << color << endl;
    for (int i = 0; i < M; i++) {
        cout << ans[i] << el;
    }

    return (0);
}

Measured memory_bytes: 21488
from queue import deque

h,w = map(int,input().split())
li = [input() for _ in range(h)]

inf = 10**10
dx = [1,0]
dy = [0,1]
que = deque()

#そのマスにたどり着くまでに色が変わった最小の回数を保存するリスト
flip_count = [[inf for i in range(w)]for j in range(h)]

if li[0][0] == "#":
    flip_count[0][0] = 1
else:
    flip_count[0][0] = 0

que.append([0,0])

while que:
    k = que.popleft()
    x = k[0]
    y = k[1]
    for i,j in zip(dx,dy):
        nx = x + i
        ny = y + j
        if nx >= w or ny >= h:
            continue
        if flip_count[ny][nx] == inf:
            que.append([nx,ny])
        if li[ny][nx] != li[y][x]:
            flip_count[ny][nx] = min(flip_count[ny][nx],flip_count[y][x]+1)
        else:
            flip_count[ny][nx] = min(flip_count[ny][nx],flip_count[y][x])

if li[-1][-1] == "#":
    flip_count[-1][-1] += 1

print(flip_count[-1][-1]//2)

Measured memory_bytes: 4080
#include <iostream>
using namespace std;
 
int main() {
	int a,b,c,d,e,f,g,h,i;
	cin>>a>>b>>c>>d>>e>>f>>g>>h>>i;
	if(a+e==b+d&&b+f==e+c&&d+h==e+g&&e+i==h+f){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

int main()
{
	string s;
	lli i,a,ans=0;
	cin>>s;
	a=s.length();
	for(i=0;i<a;i++){
		ans+=s[i]-48;
	}
	if(ans%9==0)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int k;
  cin >> k;
  long long res = 0;
  for (int a = 1; a <= k; ++a) {
    for (int b = 1; b <= k; ++b) {
      for (int c = 1; c <= k; ++c) {
        res += gcd(a, gcd(b, c));
      }
    }
  }
  cout << res << '\n';
}


Measured memory_bytes: 3648
import java.util.*;
public class Main {

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			long sum = 0;
			for(int i=n; i < 600; i+= n){
				sum += (long)n * i * i;
			}
			System.out.println(sum);
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}
}

Measured memory_bytes: 11000
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int d = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());

        // 主処理
        int result = n;
        if (d == 0 && n == 100) {
            result++;
        } else if (0 < d) {
            for (int i = 0; i < d; i++) {
                result *= 100;
            }
            if (n == 100) {
                int add = 1;
                for (int i = 0; i < d; i++) {
                    add *= 100;
                }
                result += add;
            }
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 21844
#include<stdio.h>
int maxHeapify(int);
int A[500010];
int l,r;
int N,i,L=0;
int key;

int main(void){
  scanf("%d",&N);
  for(i=1;i<=N;i++){
    scanf("%d",&A[i]);
  }
  for(i=N/2;i>0;i--){
    maxHeapify(i);
  }
  for(i=1;i<=N;i++){
    //if(i!=1)printf(" ");
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}

int maxHeapify(i){
  l=2*i;
  r=2*i+1;
  if(l<=N && A[l]>A[i])L=l;
  else L=i;
  if(r<=N && A[r]>A[L])L=r;
  if(L!=i){
    key=A[i];
    A[i]=A[L];
    A[L]=key;
    return maxHeapify(L);
  }
  return 0;
}

Measured memory_bytes: 2356
local n = io.read("*n")
local cnt = 0
for i = 1, n do
  if i <= 9 then
    cnt = cnt + 1
  elseif 100 <= i and i <= 999 then
    cnt = cnt + 1
  elseif 10000 <= i and i <= 99999 then
    cnt = cnt + 1
  end
end
print(cnt)


Measured memory_bytes: 760
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int func(int n){
    int ret = 0;
    while(n > 0){
        ret += n;
        n--;
    }
    return ret; 
}

int main(){
    int N, K;
    cin >> N >> K;
    int p[N+1];
    for(int i = 1; i < N+1; i++) cin >> p[i];
    double num[N+1];
    for(int i = 1; i < N+1; i++){
        num[i] = (double)func(p[i]);
        num[i] /= p[i];
    }
    double sum[N+1] = {0};
    for(int i = 1; i < N+1; i++) sum[i] = sum[i-1] + num[i];
    double ans = 0;
    for(int i = K; i <= N; i++){
        double m = sum[i] - sum[i-K];
        ans = max(ans, m); 
    }
    printf("%.7f\n", ans);
    return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;


 int main(){
	 
	 int h;
	 while(1){
		 int p=0;
		 int flag=1;
		 int x;
		cin >> h;
		if(h == 0) break;
		vector<vector<int> > A(5);
		for(int j = h-1; j >= 0; j--){
			for(int i = 0; i< 5; i++){
				cin >> x;
				A[i].push_back(x);
			}
		}
		for(int i = 0; i< 5; i++){
			reverse(A[i].begin(), A[i].end());
			}


		while(1){
			int flag=0;
		for(int i = 0; i < h; i++){
			int count=0;
			int mem=-1;
			//一行の処理開始
			for(int j=0; j< 5;j++){
				if(mem==A[j][i]) count++;
				else {
					mem =A[j][i];
					count = 0;
				}
				if(count > 1) {
					A[j-2][i] +=10;
					A[j-1][i] +=10;
					A[j][i] +=10;
					if(mem!=0) flag =1;
				}
			}
			for(int k = 0; k < 5 ; k++){
				if(A[k][i] >=10){
					p += A[k][i]%10;
					A[k][i]=0;
				}
			}//一行の処理終了
		}
		for(int i= 0; i < 5 ; i++){
			vector<int> B(A[i]);
			int counter=0;
			for(int j = 0 ; j < h ; j++){
				if(B[j] !=0){
					A[i][counter] = B[j];
					counter+=1;
				}
			}
			for(;counter<h; counter++){
				A[i][counter] = 0;
			}
		} 
		if(flag == 0) break;
		}
		cout <<p <<endl;
	 }
		 



	return 0;
 }

Measured memory_bytes: 1212
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
bool ins[405][405],vis[405];
int fr[N],to[N],n,m,res;
int main(){
	scanf("%d%d",&n,&m);
	fp(i,1,m)scanf("%d%d",&fr[i],&to[i]);
	fp(i,1,n){
		ins[i][i]=1;
		fd(j,m,1){
			R int u=fr[j],v=to[j];
			if(ins[i][u]&&ins[i][v]){vis[i]=1;break;}
			if(ins[i][u]||ins[i][v])ins[i][u]=ins[i][v]=1;
		}
	}
	fp(i,1,n)if(!vis[i])fp(j,i+1,n)if(!vis[j]){
		R int fl=1;
		fp(k,1,n)if(ins[i][k]&&ins[j][k]){fl=0;break;}
		res+=fl;
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 1152
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

div = [2 ** i for i in range(8)]

n = INT()
for i in reversed(div):
    if n >= i:
        print(i)
        exit()

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

const ll mod = 1e9+7;

int main() {
    int n ,x ,t;
    cin >> n >> x >> t;
    int z = (n / x);
    if(n % x != 0)
        z++;
    int result = z * t;
    cout << result << "\n";
}






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

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

  int A1, A2, A3; cin >> A1 >> A2 >> A3;
  int x = abs(A1 - A2);
  int y = abs(A2 - A3);
  int z = abs(A3 - A1);
  cout << x + y + z - max({x, y, z}) << "\n";
}

Measured memory_bytes: 256
/*Runtime Error*/
double*q,a[80],b;char s[90];
main(){
	for(q=a;~scanf("%s",s);getchar()<14&&printf("%f\n",*q--)){
/*		*s<48?b=*q--,*q=*s-47?*s-42?*s-45?*q+b:*q-b:*q*b:*q/b:sscanf(s,"%lf",++q);*/
		!sscanf(s,"%lf",q+1)?b=*q--,*q=*s-47?*s-42?*s-45?*q+b:*q-b:*q*b:*q/b:*++q;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 5e5+7;
const int mod=1e9+7;
ll qpow(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ans;
}

ll fac[M],inv[M];
ll f[M],dp[M];//错排 
ll A(int n,int m){
	return fac[m]*inv[m-n]%mod;
}
ll C(int n,int m){
	return fac[m]*inv[n]%mod*inv[m-n]%mod;
}
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int n,m,N=5e5;
  	cin>>n>>m;fac[0]=inv[0]=1;
	for(int i=1;i<=m;i++)fac[i]=fac[i-1]*i%mod,inv[i]=qpow(fac[i],mod-2);
	f[2]=1;for(int i=3;i<=m;i++)f[i]=(f[i-1]+f[i-2])*(i-1)%mod;
	ll ans=A(n,m);
	//n个位置不同 
	for(int i=1;i<=n;i++)//至少几个位置相同
	{
	//	cout<< ans<<"  "<<i<<"  - "<<C(i,n)<<"  "<<A(n-i,m-i)<<endl;
		ll tp=C(i,n)*A(n-i,m-i)%mod;
		
		if(i&1)ans=(ans-tp+mod)%mod;
		else ans=(ans+tp)%mod;
	}
	cout<<ans*A(n,m)%mod<<endl;
	return 0;
}

Measured memory_bytes: 15372
#include <iostream>

using namespace std;

int main() {
    size_t a, b;
    cin >> a >> b;
    size_t num_plug = 1;
    size_t num_tap = 0;
    while (num_plug < b) {
        num_plug += a - 1;
        ++num_tap;
    }
    cout << num_tap << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
	      Scanner sc = new Scanner(System.in);
	      int H = sc.nextInt();
	      int W = sc.nextInt();
	      int board[][] = new int[H + 2][W + 2];
	      for(int i = 1; i <= H; i++) {
	    	  	String HW = sc.next();
	    	    for(int j = 1; j <= W; j++) {
	    	    	  if(HW.charAt(j - 1) == '#') {
	    	    		  board[i][j] = 1;
	    	    	  }
	    	    }
		  }
	      sc.close();
	      
	      boolean flag = false;
	      
	      for(int i = 0; i < H + 2; i++) {
	    	    for(int j = 0; j < W + 2; j++) {
	    	    	  if(board[i][j] == 1) {
	    	    		  if(board[i][j + 1] == 0 && board[i][j - 1] == 0 && board[i + 1][j] == 0 && board[i - 1][j] == 0) {
	    	    			  flag = true;
	    	    			  break;
	    	    		  }
	    	    	  }
	    	    }
		  }
	      
	      if(flag == true) {
	    	  	System.out.println("No");
	      }else {
	    	  	System.out.println("Yes");
	      }
	      
	      System.exit(0);
	    }
}

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

#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 SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

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

    double ans = 1, ct = 0;
    while(true){
        if (h/2 != 0){
            h /= 2;
            ct += 1.0;
            ans += pow(2, ct);
        } else {
            break;
        }
    }

    cout << setprecision(20) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n, d = map(int, input().split())
x = [[0 for j in range(d)]for i in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(i):
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2
        dist = dist**(1/2)
        if dist - int(dist) == 0:
            ans += 1
print(ans)


Measured memory_bytes: 9400
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

#define PC __builtin_popcountll

int main() {
	int n;
	cin >> n;
	vector<vector<pair<int, int>>> g(n); // { v, e }
	inc(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].EB(b, i);
		g[b].EB(a, i);
	}
	int m;
	cin >> m;
	vector<pair<int, int>> c;
	inc(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		c.EB(a, b);
	}
	
	vector<int> H(n), PV(n), PE(n);
	function<void(int, int, int, int)> dfs = [&](int v, int pv, int pe, int h) {
		PV[v] = pv;
		PE[v] = pe;
		H[v] = h;
		RF(e, g[v]) {
			if(e.SE == pe) { continue; }
			dfs(e.FI, v, e.SE, h + 1);
		}
	};
	dfs(0, -1, -1, 0);
	
	vector<int> VS(n), ES(n - 1);
	inc(i, m) {
		VS[c[i].FI] ^= 1 << i;
		VS[c[i].SE] ^= 1 << i;
	}
	{
		vector<pair<int, int>> p;
		inc(i, n) { p.EB(H[i], i); }
		sort(RALL(p));
		RF(e, p) {
			int v = e.SE;
			if(PE[v] == -1) { continue; }
			ES[PE[v]] ^= VS[v];
			VS[PV[v]] ^= VS[v];
		}
	}
	
	LL ans = 0;
	inc(B, 1 << m) {
		int t = 0;
		inc(i, n - 1) { if((ES[i] & B) != 0) { t++; } }
		ans += (PC(B) % 2 == 0 ? +1 : -1) * (1LL << (n - 1 - t));
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 764
def gcd(a,b):
  if b == 0:
    ret = a
  else:
    ret = gcd(b, a%b)
  return ret

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
gu = [0 for i in range(N)]
gl = [0 for i in range(N)]
if N == 2:
  if A[0] > A[1]:
    print(A[0])
  else:
    print(A[1])
else:
  max = 0
  gu[0] = A[0]
  for i in range(1,N-1):
    y = gu[i-1]
    x = A[i]
    gu[i] = gcd(y,x)
    
  gl[0] = A[N-1]
  for i in range(1,N-1):
    y = gl[i-1]
    x = A[N-1-i]
    gl[i] = gcd(y,x)

  for i in range(N):
    if i == 0:
      x = gl[N-2]
    elif i == N-1:
      x = gu[N-2]
    else:
      y = gu[i-1]
      x = gl[N-2-i]
      x = gcd(y,x)
    if max < x:
      max = x
  print(max)


Measured memory_bytes: 14076
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ul unsigned long long int
#define vi vector<int>
#define vl vector<int64_t>
#define all(x) x.begin(),x.end()
#define pb push_back
#define fo(x,a,b) for(int x=a; x<b; x++)
#define rfo(x,a,b) for(int x=a; x>=b; x--)
#define fi first
#define sec second
#define mp make_pair
int sgn(int x) { return x>0 ? 1 : ( x<0 ? -1 : 0); }
typedef pair<int,int> pairs;
double pi = 3.14159265358979323846;
ll mod = 1000000007;

void solve()
{
    ll n;
    cin>>n;
    ll ans=0;
    int ma=0;
    vi a(n);
    fo(i,0,n)
    {
        cin>>a[i];
        ma=max(ma,a[i]);
        ans+=ma-a[i];
    }
    cout<<ans;
    cout<<"\n";
    return;
}
int main()
{
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    //cin>>t;
    //while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3976
import itertools
import math
import fractions
import functools
import copy

N, T = map(int, input().split())
c= []
t = []
for i in range(N):
     ci, ti = map(int, input().split())
     c.append(ci)
     t.append(ti)

cost = 10**10
for i in range(N):
    if t[i] <= T:
        cost = min(cost,c[i])
if cost == 10**10:
    print("TLE")
else:print(cost)

Measured memory_bytes: 63980
# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())

class UnionFindTree():
    
    def __init__(self, N):
        self.parent = [-1]*(N+1)
        self.rank = [1]*(N+1)
        self.size = [1]*(N+1)
  
    def find(self, i):
        if self.parent[i] == -1:
            group = i
        else:
            group = self.find(self.parent[i]) 
            self.parent[i] = group
        return group
      
    def unite(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px != py:
            if self.rank[px] == self.rank[py]: # rank is same
                self.rank[px] += 1
            elif self.rank[px] < self.rank[py]:
                px, py = py, px
                
            self.parent[py] = px
            self.size[px] += self.size[py]
    
    def getsize(self, x):
        return self.size[self.find(x)]
    
    def groups(self, index1=True):
        return set([self.find(i) for i in range(0+index1, N+index1)])

N, M = inpl()
P = list(inpl())

UFT = UnionFindTree(N)
for m in range(M):
    x, y = inpl()
    UFT.unite(x, y)

ans = sum([UFT.find(i) == UFT.find(p) for i, p in enumerate(P, start=1)])
print(ans)

Measured memory_bytes: 102380
#include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include <queue>
#include<algorithm>
typedef long long int ll;
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EFOR(i,a,b) for (int i=(a);i<=(b);i++)
const ll MOD = (10*10*10*10*10*10*10*10*10+7);
    int ans=0,id;
    int N,M;
    int a[52],b[520],c[52],d[52];

int main(){
    ios_base::sync_with_stdio(false);
    REP(i,3)cin>>a[i];
    sort(a,a+3);
    a[0]+a[1]==a[2]?cout<<"Yes":cout<<"No";
    //cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };


int gcd(int a, int b) {
	if (a == 0 || b == 0)return 0;
	if (a%b == 0)return b;
	return gcd(b, a%b);
}

int g1[101010];
int g2[101010];

int main() {
	int n;
	cin >> n;
	vector<int>a(n);

	rep(i, 0, n) {
		cin >> a[i];
	}

	g1[0] = a[0];
	rep(i, 1, n) {
		g1[i] = gcd(g1[i-1],a[i]);
	}
	g2[0] = a[n - 1];
	rep(i,1,n) {
		g2[i] = gcd(g2[i-1], a[n-1-i]);
	}
	
	int ans = max(g1[n-2],g2[n-2]);
	ans = max(ans,g1[n-1]);
	rep(i, 1, n-1) {
		int temp = gcd(g1[i-1],g2[n-i-2]);
		ans = max(temp, ans);
	}
	cout << ans << endl;
	

	


	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

bool check(char a, char b) {
	return a > b;
}

int kuraiwa(int n) {
	int ans = 0;
	while (n > 0) {
		ans += n % 10;
		n /= 10;
	}
	return ans;
}

bool kaibun(int n) {
	int a[5];
	for (int i = 0;i < 5;i++) {
		a[i] = n % 10;
		n /= 10;
	}
	if (a[0] == a[4] && a[1] == a[3]) {
		return true;
	}
	else {
		return false;
	}
}

int main() {
	int a, b;
	cin >> a;
	vector<string>s(a);
	rep(i, a) {
		cin >> s[i];
	}
	cin >> b;
	vector<string>t(b);
	rep(i, b) {
		cin >> t[i];
	}
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	int j = 0;
	int cnt;
	int max = 0;
	rep(i, a) {
		cnt = 1;
		if (i != a - 1) {
			while (s[i] == s[i + 1]) {
				cnt++;
				i++;
				if (i == a - 1) {
					break;
				}
			}
		}
		for (j;j < b ;j++) {
			if (s[i] == t[j]) {
				cnt--;
				if (j < b - 1) {
					while (t[j] == t[j + 1]) {
						cnt--;
						j++;
						if (j >= b - 1) {
							break;
						}
					}
				}
				else {
					break;
				}
			}
			if (s[i] < t[j]) {
				break;
			}
		}
		if (max < cnt) {
			max = cnt;
		}
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define OP ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
const int inf = int(1e9);
const int mod = inf + 7;
const double PI = acos(-1.0);
using namespace std;
const int N = 1e5 + 155;
 
void solve(){
	int n;
	cin >> n;
	double ans;
	if (n & 1) {
		ans = 1.0 * (n / 2 + 1) / (n);
	}
	else ans = 0.5;
	printf("%.15f", ans);	
}
 
int main(){
    OP
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from bisect import bisect_left
import sys,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    #根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
        
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

n,m,k = inpl()
ab = [inpl() for i in range(m)]
cd = [inpl() for i in range(k)]
uf = UnionFind(n)
fr = [[] for i in range(n)]
bl = [[] for i in range(n)]
for i in range(m):
    a,b = ab[i]
    fr[a-1].append(b-1)
    fr[b-1].append(a-1)
    uf.union(a-1,b-1)
for i in range(k):
    c,d = cd[i]
    bl[c-1].append(d-1)
    bl[d-1].append(c-1)
# print(fr,bl)
for i in range(n):
    s = set()
    cnt = 0
    for j in fr[i]:
        s.add(j)
    for j in bl[i]:
        if uf.same(i,j) and not j in s:
            cnt += 1
    print(uf.size(i)-1 - len(s) - cnt)
# print(uf.members(0))

Measured memory_bytes: 131672
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n , c = 1, d = 0;
    cin >> n;
    int a[n + 1] , b[n + 1];
    for ( int i = 1 ; i <= n ; i++ ) {
        cin >> a[i];
        b[i] = 0;
    }
    while ( c != 2 ) {
        if ( b[c] == 1 ) {
            cout << -1;
            return 0;
        }
        b[c] = 1;
        c = a[c];
        d++;
    }
    cout << d;
}


Measured memory_bytes: 1024
a,b,x = map(int,input().split())
import numpy as np
if x<=(a*a*b)/2:
    A = 2*x/(a*b*b)
    Z = A
    print(90-np.arctan(Z)*180/(np.pi))
else:
    A = 2*a*a*b-2*x
    B = A/(a*a*a)
    Z = B
    print(np.arctan(Z)*180/np.pi)

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

#define int long long
 	
const int N = 1e5 + 11;
int p[N], sz[N];

int get(int x){
  if (p[x] == x) return x;
  return p[x] = get(p[x]);	
}

void unite(int x, int y){
   x = get(x), y = get(y);
   if(sz[x] < sz[y]) swap(x, y);
   sz[x] += sz[y];
   p[y] = x;
}

int32_t main(){
	int n, m, q;
	cin >> n >> m;
	for(int i = 0; i < n; i++){
	   p[i] =  i;
	   sz[i]  = 0;	
	}
	for(int i = 0; i < m; i++){
	   int x, y;
	   cin >> x >> y;
	   unite(x, y);
	}
   cin >> q;
   for(int i = 0; i < q; i++){
	  int start, end;
	  cin >> start >> end;
	  if (get(start) == get(end)) cout << "yes" << endl;
	  else  cout << "no" << endl;   
	}
}



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

signed main() {
    int H, W; cin >> H >> W;
    int A[H][W], B[H][W];
    
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            cin >> A[i][j];
        }
    }
    
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            cin >> B[i][j];
        }
    }
    
    int C[H][W];
    
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            C[i][j] = A[i][j]-B[i][j];
        }
    }
    
    bool dp[H][W][32001];
    
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            for (int k=0; k<=32000; k++) {
                dp[i][j][k] = false;
            }
        }
    }
    
    dp[0][0][C[0][0]+16000] = true;
    dp[0][0][-C[0][0]+16000] = true;
    
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            if (i==0 && j==0) {
                continue;
            }
            
            if (i>0) {
                for (int k=0; k<=32000; k++) {
                    if (dp[i-1][j][k]) {
                        if (k+C[i][j]<=32000) {
                            dp[i][j][k+C[i][j]] = true;
                        }
                        if (k-C[i][j]>=0) {
                            dp[i][j][k-C[i][j]] = true;
                        }
                    }
                }
            }
            
            if (j>0) {
                for (int k=0; k<=32000; k++) {
                    if (dp[i][j-1][k]) {
                        if (k+C[i][j]<=32000) {
                            dp[i][j][k+C[i][j]] = true;
                        }
                        if (k-C[i][j]>=0) {
                            dp[i][j][k-C[i][j]] = true;
                        }
                    }
                }
            }
        }
    }
    
    int ans = 1000000000;
    
    for (int k=0; k<=32000; k++) {
        if (dp[H-1][W-1][k]) {
            ans = min(ans, abs(k-16000));
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 200448
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  sort (d.begin(), d.end());
  int ans = 1;
  for (int i = 0; i < N - 1; i++) {
    if (d.at(i) < d.at(i + 1)) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n = input()
            if n == 0:
                break
            divisors = set()
            for i in range(1, int(math.sqrt(n))+1):
                if n % i == 0:
                    f = n / i
                    if i != 1 and i % 2 == 1:
                        divisors.add(i)
                    if f != 1 and f % 2 == 1:
                        divisors.add(f)
            # print divisors
            print len(divisors)
        
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Measured memory_bytes: 4680
As, Bs = readlines.drop(1).map{|l| l.split.map(&:to_i)}.transpose

bs, is = Bs.each_with_index.sort.transpose
as = is.map{|i| As[i]}.inject([0]){|s, a| s << s.last + a}.drop(1)
puts is.all?{|i| as[i] <= bs[i]} ? 'Yes' : 'No'

Measured memory_bytes: 47984
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define repl(k,n) for(k=1;k<n;++k)

int main() {
	int X;//比較基準値
	int N;//何個あるか
	int i;
	int k;
	int j;
	int t;
	int h;
	cin >> X >> N;
	vector<int> p(N);//比較対象外との距離の差
	rep(i, N) {
		cin >> p[i];
	}
	repl(k, 2 * N + 3) {
		t = 0;
		h = -(k * pow(-1, k)) / 2;
		rep(j, N) {
			if (X + h == p[j]) {
				j = N;
				t = 1;
			}
		}
		if (t == 0) {
			cout << X + h;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3980
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int n;
	while(cin >> n, n){
		vector< pair<int, int> >v;
		v.push_back(make_pair(0, 0));
		int minx = 0;
		int maxx = 0;
		int miny = 0;
		int maxy = 0;
		for(int i = 1; i < n; i++){
			int p, q; cin >> p >> q;
			if (q == 0) v.push_back(make_pair(v[p].first - 1, v[p].second));
			else if (q == 1) v.push_back(make_pair(v[p].first, v[p].second - 1));
			else if (q == 2) v.push_back(make_pair(v[p].first + 1, v[p].second));
			else if (q == 3) v.push_back(make_pair(v[p].first, v[p].second + 1));
			minx = min(minx, v[i].first);
			maxx = max(maxx, v[i].first);
			miny = min(miny, v[i].second);
			maxy = max(maxy, v[i].second);
		}
		cout << maxx - minx + 1 << ' ' << maxy - miny + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<ll> a(n), b(n + 1);
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		b[i + 1] = b[i] + a[i];
	}
	vector<ll> c;
	c.reserve(n * (n + 1) / 2);
	for(int i = 0; i < n; ++i){
		for(int j = i + 1; j <= n; ++j){ c.push_back(b[j] - b[i]); }
	}
	sort(c.begin(), c.end());
	ll answer = 0;
	int lo = 0, hi = c.size();
	for(int i = 60; i >= 0; --i){
		const int mid = partition_point(
			c.begin() + lo, c.begin() + hi,
			[&](ll x) -> bool {
				const ll mask = answer | (1ll << i);
				return (x & mask) != mask;
			}) - c.begin();
		if(hi - mid >= k){
			answer |= (1ll << i);
			lo = mid;
		}else{
			for(int j = lo; j < hi; ++j){ c[j] &= ~(1ll << i); }
			sort(c.begin() + lo, c.begin() + hi);
		}
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 4224
open Scanf
open Printf

let pair a b = a, b

let rec scan_list = function
  | 0 -> []
  | n -> scanf "%d %d\n" (fun a b -> (a,b) :: scan_list (n-1))

let rec f count amin = function
  | [] -> count
  | (a,b) :: xs -> if a <= amin 
    then f count amin xs
    else f (count + 1) (b-1) xs

let () = let _,m = scanf "%d %d\n" pair in
  let lst = scan_list m in
  printf "%d\n" (f 0 0 @@ List.sort (fun (a1,b1) (a2,b2) -> compare (b1,a1) (b2,a2)) lst)

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el cout << "\n"
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);

int main()
{
	IOS;
    cout.precision(30);
    int n,k; cin >> n >> k; vector<ll> A(n,0);
    for (int i=0;i<n;i++)
    {
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    ll ans=1e15;
    k--;
    for (int i=0;i+k<n;i++)
    {
        ans=min(ans,A[i+k]-A[i]+min(abs(A[i]),abs(A[i+k])));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
        int a;
        cin >> a;
        return a;
};

void inputArray(int * p, int a){
        rep(i, a){
                cin >> p[i];
        }
};

void inputVector(vector<int> * p, int a){
        rep(i, a){
                int input;
                cin >> input;
                p -> push_back(input);
        }
}

template <typename T>
void output(T a, int precision) {
        if(precision > 0){
                cout << setprecision(precision)  << a << "\n";
        }
        else{
                cout << a << "\n";
        }
}

int main(int argc, const char * argv[]) {

        // source code
        int n,m;

        n=inputValue();
        m=inputValue();


        int lmax=0;
        int rmin=n;
        rep(i,m)
        {
                int l = inputValue();
                int r = inputValue();
                if(l>lmax)lmax=l;
                if(r<rmin)rmin=r;
        }
        output<int>(rmin-lmax>=0?rmin-lmax+1:0,0);


        return 0;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}

main :: IO ()
main = print =<< calc . words <$> getLine
    where
        calc [x,"+",y] = read x + read y
        calc [x,"-",y] = read x - read y


Measured memory_bytes: 508
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 cnt[128];
int main() {
  string s;
  cin >> s;
  for (char c : s) cnt[int(c)]++;
  i64 N = cnt[int('N')],
      W = cnt[int('W')],
      S = cnt[int('S')],
      E = cnt[int('E')];

  bool x = N > 0 && S > 0,
       y = N == 0 && S == 0,
       z = W > 0 && E > 0,
       w = W == 0 && E == 0;

  if ((x || y) && (z || w)) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int D;//日数
	uint32_t c[26];// 満足度低下係数
	uint32_t s[365][26]; //d日目にコンテストタイプiを実施したときの満足度増加幅
	uint32_t t[365]; //D日目にどのコンテストタイプを実施するか
	
	// 入力
	cin >> D;
	for(int i = 0; i < 26; ++i) {
		cin >> c[i];
	}
	for(int i = 0; i < D; ++i) {
		for(int j = 0; j < 26; ++j) {
			cin >> s[i][j];
		}
	}
	//for(int i = 0; i < D; ++i) {
	//	cin >> t[i];
	//}
	
	//出力
	for(int d = 0; d < D; ++d) {
		cout << (d % 26 + 1) << endl;
	}

	return 0;
}



Measured memory_bytes: 3228
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(100000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def dfs(i, a, b, c, N, A, B, C, L):
    if i >= N:
        if a == 0 or b == 0 or c == 0:
            return INF
        return abs(A - a) + abs(B - b) + abs(C - c)

    ret = INF
    ret = min(ret, dfs(i + 1, a + L[i], b, c, N, A, B, C, L) + (10 if a > 0 else 0))
    ret = min(ret, dfs(i + 1, a, b + L[i], c, N, A, B, C, L) + (10 if b > 0 else 0))
    ret = min(ret, dfs(i + 1, a, b, c + L[i], N, A, B, C, L) + (10 if c > 0 else 0))
    ret = min(ret, dfs(i + 1, a, b, c, N, A, B, C, L))

    return ret


def main():
    N, A, B, C = map(int, input().split())
    L = [int(input()) for _ in range(N)]

    print(dfs(0, 0, 0, 0, N, A, B, C, L))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3952