akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	K := nextInt()
	var ans float64
	for i := 1; i <= N; i++ {
		p := i
		var cc float64
		for p < K {
			p = p * 2
			cc++
		}
		ans += (1.0 / math.Pow(2, cc))
	}
	fmt.Printf("%.12f\n", ans/float64(N))
}

var dy = []int{1, 0, -1, 0, 0}
var dx = []int{0, 1, 0, -1, 0}
var inf = int(1e9)

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type pairs []Pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

var nextReader func() []byte

func init() {
	nextReader = newScanner()
	log.SetFlags(log.Lshortfile)
}

func newScanner() func() []byte {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() []byte {
		r.Scan()
		return r.Bytes()
	}
}
func nextBytes() []byte {
	return nextReader()
}

func nextString() string {
	return string(nextReader())
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(string(nextReader()), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(string(nextReader()))
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(string(nextReader()), 64)
	return f
}


Measured memory_bytes: 640
from sys import exit
from collections import Counter
N = int(input())
Alist = Counter(list(map(int, input().split())))
over_2 = []
for A in sorted(Alist.items(), reverse=True):
    if A[1] >= 4:
        if len(over_2) == 0:
            print(A[0] ** 2)
        else:
            print(A[0] * over_2[0])
        exit()
    elif A[1] >= 2:
        over_2.append(A[0])
        if len(over_2) == 2:
            print(over_2[0] * over_2[1])
            exit()
    else:
        continue
else:
    print(0)


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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

int N;
vector<Int> A;

int main(){
	cin>>N;
	A.assign(N,0);
	REP(i,N)cin>>A[i];
	sort(ALL(A));
	int ans = 0;
	Int s = 0;
	int stop_id = 0;
	REP(i,N){
		if(s*2<A[i])stop_id = i;//i, i+1, i+2, ...
		s += A[i];
	}
	cout<<N - stop_id<<endl;
	return 0;
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

ll DP[3][110][5];

int main(){
    string S;
    ll K;
    cin >> S >> K;
    ll N = S.length();

    REP(i,N+1){
        REP(j,3){
            REP(k,2){
                DP[k][i][j] = 0;
            }
        }
    }

    DP[0][0][0] = 1;
    REP(i,N){
        int n = S[i] - '0';
        for(int j = 0; j <= 3; j++){
            for(int k = 0; k < 10; k++){
                if(k < n){
                    if(k == 0){
                        DP[1][i+1][j] += DP[0][i][j];
                        DP[1][i+1][j] += DP[1][i][j];
                    }
                    else{
                        DP[1][i+1][j+1] += DP[0][i][j];
                        DP[1][i+1][j+1] += DP[1][i][j];
                    }
                }
                else if(k == n){
                    if(k == 0){
                        DP[0][i+1][j] += DP[0][i][j];
                        DP[1][i+1][j] += DP[1][i][j];
                    }
                    else{
                        DP[0][i+1][j+1] += DP[0][i][j];
                        DP[1][i+1][j+1] += DP[1][i][j];
                    }
                }
                else{
                    DP[1][i+1][j+1] += DP[1][i][j];
                }
            }
        }
    }

    ll ans = 0;
    REP(i,2){
        ans += DP[i][N][K];
    }

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


Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
int lst[2005], to[4005], pre[4005], tot;
int x[2005], y[2005], cnt[4005];
std::vector<int> path[2005], bel[2005];
bool del[2005], vis[4005];
inline void add_edge(int u, int v)
{
	to[tot] = v; 
	pre[tot] = lst[u];
	lst[u] = tot++;
}
bool dfs(int u, int en, std::vector<int> &e, int fa = -1)
{
	if (u == en)
		return true;
	for (int i = lst[u]; ~i; i = pre[i])
	{
		if (to[i] == fa)
			continue;
		e.push_back(i);
		if (dfs(to[i], en, e, u))
			return true;
		e.pop_back();
	}
	return false;
}
int main()
{
	// freopen("AGC025-E.in", "r", stdin);
	memset(lst, -1, sizeof(lst));
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i < n; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		add_edge(--u, --v);
		add_edge(v, u);
	}
	for (int i = 0; i < m; i++)
	{
		scanf("%d%d", x + i, y + i);
		dfs(--x[i], --y[i], path[i]);
		for (int e : path[i])
		{
			cnt[e >> 1]++;
			bel[e >> 1].push_back(i);
		}
	}
	int ans = 0;
	for (int i = 0; i < n - 1; i++)
		ans += std::min(2, cnt[i]);
	printf("%d\n", ans);
	for (int t = 0; t < m; t++)
	{
		int idx = -1;
		for (int i = 0; i < n - 1 && -1 == idx; i++)
		{
			if (cnt[i] == 1 && vis[i << 1] != vis[i << 1 | 1])
				idx = i << 1 | vis[i << 1];
		}
		for (int i = 0; i < n - 1 && -1 == idx; i++)
		{
			if (cnt[i])
				idx = i << 1;
		}
		int e = idx >> 1;
		while (del[bel[e].back()])
			bel[e].pop_back();
		int p = bel[e].back();
		bool rev = false;
		for (int i : path[p])
		{
			if (i >> 1 == e)
				rev = i != idx;
		}
		if (rev)
		{
			std::swap(x[p], y[p]);
			for (int &i : path[p])
				i ^= 1;
		}
		for (int i : path[p])
		{
			cnt[i >> 1]--;
			vis[i] = true;
		}
		del[p] = true;
	}
	for (int i = 0; i < m; i++)
		printf("%d %d\n", x[i] + 1, y[i] + 1);
	return 0;
}


Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
/* constexpr ll MOD = ll(1e9) + 7LL; */
constexpr ll MOD = 998244353LL;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < (int)v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

struct BIT {
    vector<int> data;
    int sz;

    BIT(vector<int>& a) {
        int n = a.size();
        sz = 1;
        while (n > sz) {
            sz *= 2;
        }
        data.resize(sz+1, 0);
        REP(i, n) {
            update(i, a[i]);
        }
    }

    int getval(int left, int right) {
        return sum(right+1 - 1) - sum(left+1 - 1);
    }

    void update(int n, int val) {
        ++n;
        while (n <= sz) {
            data[n] += val;
            n += n & -n;
        }
    }

    int sum(int n) {
        int tmp = 0;
        while (n > 0) {
            tmp += data[n];
            n -= n & -n;
        }
        return tmp;
    }
};

void solve() {
    ll n, q;
    cin >> n >> q;
    vll c(n);
    cin >> c;
    vector<pair<pll, int>> rl(q);
    REP(i,q){
        ll l,r;
        cin >> l >> r;
        --l;--r;
        rl[i] = make_pair(make_pair(r,l), i);
    }
    sort(ALL(rl));
    ll initr = rl[0].first.first;
    unordered_map<ll, ll> ma;
    REP(i, initr+1) {
        ma[c[i]] = i;
    }
    vint a(n, 0);
    for (auto elem: ma) {
        a[elem.second]++;
    }
    vint ans(q, 0);
    BIT st(a);
    ll prevr = initr;
    REP(i, q) {
        ll nowr = rl[i].first.first, nowl = rl[i].first.second;
        while (nowr != prevr){
            ++prevr;
            if (ma.find(c[prevr]) != ma.end()) {
                a[ma[c[prevr]]]--;
                st.update(ma[c[prevr]], -1);
                ma[c[prevr]] = prevr;
                a[ma[c[prevr]]]++;
                st.update(ma[c[prevr]], +1);
            } else {
                ma[c[prevr]] = prevr;
                a[ma[c[prevr]]]++;
                st.update(ma[c[prevr]], +1);
            }
        }
        ans[rl[i].second] = st.getval(nowl, nowr + 1);
    }
    REP(i,q) {
        cout << ans[i] << endl;
    }
}

int main() {
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}


Measured memory_bytes: 45056
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define inrep int t;cin>>t; while(t--)
#define pb emplace_back
using namespace std;
using namespace __gnu_pbds; 


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;
const ll MOD = 1e9+7;
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {

    for ( unsigned   i=0; i<v.size(); i++ )
        in>>v[i];
    return in;
}

ll power(ll x, ll y,ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2,m)%m; 
    p = (p * p)%m; 
  
    return (y%2 == 0)? p : (x * p)%m ; 
} 

ll modInverse(ll a, ll m) 
{ 
        // If a and m are relatively prime, then modulo inverse 
        // is a^(m-2) mode m 
    return power(a, m-2,m); 
} 
  
// To compute x^y under modulo m 
ll dp[3001][3001][2];
ll a[3001];
ll calc(int i,int j,int k)
{
    if(i>j)
    {
        return 0;
    }
    if(dp[i][j][k]!=-1)
        return dp[i][j][k];
    if(k==0)
    {
        dp[i][j][k] = max(a[i]+calc(i+1,j,1-k),a[j]+calc(i,j-1,1-k));
    }
    else
    {
        dp[i][j][k] = min(calc(i+1,j,1-k)-a[i],calc(i,j-1,1-k)-a[j]);
    }
    return dp[i][j][k];
}
int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    mset(dp,-1);
    cout<<calc(0,n-1,0);
    
    
    return 0;
}

Measured memory_bytes: 141184
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+8+1;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//グローバル変数


//ライブラリ挿入
const int N_MAX=1e+3;
const int H_MAX=1e+4;
vector<vector<int>> dp(N_MAX+1,vector<int>(2*H_MAX+1,INF));

int main(){
    int H,N;
    cin >> H >> N;
    vector<int> A(N),B(N);
    REP(i,N) cin >> A[i] >> B[i];
    REP(i,N+1) dp[i][0]=0;


    REP(i,N){
        REP2(h,1,2*H_MAX+1){
            if(A[i]<=h) dp[i+1][h]=min(dp[i][h],dp[i+1][h-A[i]]+B[i]);
            else dp[i+1][h]=dp[i][h];
        }
    }

    int ans=INF;
    REP2(h,H,2*H_MAX+1){
        ans=min(ans,dp[N][h]);
    }

    cout << ans << endl;
    
    
}

Measured memory_bytes: 78720
use proconio::input;

fn mod_pow(a: u64, p: u64, m: u64) -> u64 {
    if p == 0 {
        1
    } else {
        let half = mod_pow(a, p/2, m);
        let res = half * half % m;
        if p % 2 == 0 { res } else  { res * a % m }
    }
}

fn main() {
    input! {
        n : u64,
        k : usize
    };
    let mut a = [0; 100001];
    let m : u64 = 1000000007;
    let mut res : u64 = 0;
    for i in (1..=k).rev() {
        a[i] = mod_pow((k/i) as u64, n, m);
        let mut j = 2 * i;
        while j <= k {
            a[i] = (a[i] + m - a[j]) % m;
            j += i;
        }
        res = (res + a[i] * i as u64) % m;
    }
    println!("{}", res);
}


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

int main()
{
	int n,m;
	int s,t;
	int i,j,flag;
	vector<int> x,y,a,b,p,q;
	while(cin>>n,n){
		a.clear();
		b.clear();
		cin>>m;
		cin>>s>>t;
		a.push_back(s);
		b.push_back(t);
		for(i=0;i<m-1;i++){
			cin>>s>>t;
			a.push_back(s-a[0]);
			b.push_back(t-b[0]);
		}
		a[0]=a[0]-a[0];
		b[0]=b[0]-b[0];
		for(i=0;i<n;i++){
			cin>>m;
			flag=0;
			x.clear();
			y.clear();
			p.clear();
			q.clear();
			for(j=0;j<m;j++){
				cin>>s>>t;
				x.push_back(s);
			    y.push_back(t);
			}
			s=x[0];
			t=y[0];
			for(j=0;j<m;j++){
				p.push_back(x[j]-s);
			    q.push_back(y[j]-t);
			}
			for(int c=0;c<4;c++){
				for(j=0;j<m;j++){
					s=p[j];
					p[j]=-q[j];
					q[j]=s;
				}
				if(p==a&&q==b){
					cout<<i+1<<endl;
					flag=1;
					break;
				}
			}		
			if(flag){
				flag=0;
				continue;
			}
			reverse(x.begin(),x.end());
			reverse(y.begin(),y.end());
			for(j=0;j<m;j++){
				p[j]=x[j]-x[0];
			    q[j]=y[j]-y[0];
			}
			for(int c=0;c<4;c++){
				for(j=0;j<m;j++){
					s=p[j];
					p[j]=-q[j];
					q[j]=s;
				}
				if(p==a&&q==b){
					cout<<i+1<<endl;
					flag=1;
					break;
				}
			}
		}
		cout<<"+++++"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1224
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if a > b:
    aa = a - t * v
    bb = b - t * w
    if aa > bb:
        print('NO')
    else:
        print('YES')
elif a < b:
    aa = a + t * v
    bb = b + t * w
    if aa < bb:
        print('NO')
    else:
        print('YES')
else:
    print('YES')


Measured memory_bytes: 9188
a,b = map(int,input().split())
import bisect
A=list(map(int,input().split()))
A.sort(reverse=True)
#print(A)

C=[]
#D=[]
for i in range(b):
    c,d=map(int,input().split())
    #insert_index = bisect.bisect_left(A,d)
    #A.extend([for i in ])
    C.append([c,d])
    #D.append(d)

C2=sorted(C, key=lambda x: x[1],reverse=True)

arr=[]
num=0
cnum=0
#for i in C2:
while len(arr)<a:
    if cnum>len(C2)-1:
        arr.append(A[num])
        num+=1
    elif num>len(A)-1:
        arr.extend([C2[cnum][1] for _ in range(C2[cnum][0])])
        cnum+=1
    elif C2[cnum][1]<A[num]:
        arr.append(A[num])
        num+=1
    else:
        arr.extend([C2[cnum][1] for _ in range(C2[cnum][0])])
        cnum+=1
    #if len(arr)>=a:
    #    break
    #print(arr)


#print(arr)
print(sum(arr[:a]))


Measured memory_bytes: 27592
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
int main(){
    int n,k,x,y,ans;
    cin >> n >> k >> x >> y;

    if(k < n){
        ans = x*k + y*(n-k);
    }else{
        ans = x*n;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int N, Ma, Mb;
int a[50], b[50], c[50];
int dp[410][410];


void makeDP(){
	rep(i, 0, 410) fill(RNG(dp[i], 0, 410), INF);
	rep(i, 0, N){
		repr(j, 410, 1)
			repr(k, 410, 1)
				if(dp[j][k] != INF) chmin(dp[j+a[i]][k+b[i]], dp[j][k]+c[i]);
		chmin(dp[a[i]][b[i]], c[i]);
	}
}


int solve(){
	int ans = INF;
	repe(i, 1, 40)
		if(i*Ma <= 400 && i*Mb <= 400) chmin(ans, dp[i*Ma][i*Mb]);
	if(ans == INF) return -1;
	return ans;
}


signed main(){
	cin >> N >> Ma >> Mb;
	rep(i, 0, N) cin >> a[i] >> b[i] >> c[i];

	makeDP();

	cout << solve() << endl;

	return 0;
}

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


int main(){
  int64_t N,M;
  cin >> N >> M;
  vector<pair<int64_t,int64_t>> edge(M);
  vector<int64_t> Ans(N,100000);
  vector<vector<int64_t>> A(N, vector<int64_t>(0));
  queue<int64_t> Q;
  for(int64_t i=0;i<M;i++){
    cin >> edge.at(i).first >> edge.at(i).second;
    edge.at(i).first--;
    edge.at(i).second--;
    A.at(edge.at(i).first).push_back(edge.at(i).second);
    A.at(edge.at(i).second).push_back(edge.at(i).first);
  }
  Ans.at(0)=0;
  Q.push(0);
  while(!Q.empty()){
    int64_t q=Q.front();
    Q.pop();
    for(int64_t i=0;i<A.at(q).size();i++){
      if(Ans.at(A.at(q).at(i))==100000){
        Ans.at(A.at(q).at(i))=q;
        Q.push(A.at(q).at(i));
      }
    }
  }
  cout << "Yes" << endl;
  for(int64_t i=1;i<N;i++){
    cout << Ans.at(i)+1 << endl;
  }
}

Measured memory_bytes: 15872
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	class Edge implements Comparable<Edge> {
		int v1;
		int v2;
		long cost;

		public Edge(int v1_, int v2_, long cost_) {
			v1 = v1_;
			v2 = v2_;
			cost = cost_;
		}

		public int compareTo(Edge arg0) {
			return Long.compare(cost, arg0.cost);
		};
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[][] a = new long[n][n];
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				a[i][j] = sc.nextLong();
			}
		}
		boolean ok = true;
		for (int m = 0; m < n; ++m) {
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < n; ++j) {
					ok &= a[i][m] + a[m][j] >= a[i][j];
				}
			}
		}
		if (!ok) {
			System.out.println(-1);
			return;
		}

		ArrayList<Edge> list = new ArrayList<>();
		for (int i = 0; i < n; ++i) {
			for (int j = i + 1; j < n; ++j) {
				list.add(new Edge(i, j, a[i][j]));
			}
		}
		Collections.sort(list);

		long[][] d = new long[n][n];
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if (i == j)
					continue;
				d[i][j] = Long.MAX_VALUE / 10;
			}
		}

		long ans = 0;
		for (Edge e : list) {
			if (d[e.v1][e.v2] == e.cost)
				continue;
			ans += e.cost;
			d[e.v1][e.v2] = e.cost;
			d[e.v2][e.v1] = e.cost;
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < n; ++j) {
					d[i][j] = Math.min(d[i][j], d[i][e.v1] + d[e.v2][j] + e.cost);
					d[i][j] = Math.min(d[i][j], d[i][e.v2] + d[e.v1][j] + e.cost);
				}
			}
		}
		System.out.println(ans);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

Measured memory_bytes: 58860
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main(void){
    int n, x, t;
  cin >> n >> x >> t;
  if(n % x == 0) cout << t * (n / x) << endl;
  else cout << t * (n / x) + t * ((n % x) / (n % x)) << endl;
    return 0;
}

Measured memory_bytes: 3584
import itertools

N, M = map(int, input().split())
cakes = []
for _ in range(N):
    cakes.append(tuple(map(int, input().split())))

ans = 0
for t in itertools.product([1, -1], repeat=3):
    tmp = [sum(cakes[i][j] * t[j] for j in range(3)) for i in range(N)]
    ans = max(ans, sum(sorted(tmp, reverse=True)[:M]))
print(ans)

Measured memory_bytes: 3316
# n: 参加者人数
# k: 初期ポイント
# q: ラウント回数
n, k, q = map(int, input().split())
data = [ int(input()) for _ in range(q) ]

table = [k] * n

for winnner in data:    
    table[winnner - 1] += 1

for j in range(n):
    table[j] -= q

for k in range(n):
    if table[k] > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 56664
#!/usr/bin/env python3
import sys
import collections

def solve(N: int, K: int, A: "List[int]"):
    r = 0

    c = collections.Counter(A).most_common()
    while K < len(c):
        _, cnt = c.pop()
        r+=cnt
    return r


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, K, A))

if __name__ == '__main__':
    main()


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

int main() {
   int a,b,c;
   cin>> a >> b >>c;
   if(a>b) {
      swap(a,b);
   }
   if(c<b) {
      swap(b,c);
   } 
   if(a>b) {
      swap(a,b);
   }
  cout<< a <<" "<< b <<" "<< c <<endl;
  return 0;
  
  
  
}


Measured memory_bytes: 3092
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

typedef int SumType;
class Sum2D {
public:
    Sum2D() {}
    Sum2D(const vector<vector<SumType>> &a)
        :h((int)a.size()), w((int)a[0].size()), s(h + 1, vector<SumType>(w + 1))
    {
        for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j)
            s[i][j] = s[i - 1][j] + s[i][j - 1] + a[i - 1][j - 1] - s[i - 1][j - 1];
    }

    SumType get(int sy, int sx, int ty, int tx) {
        return s[ty][tx] - s[sy][tx] - s[ty][sx] + s[sy][sx];
    }
private:
    int h, w;
    vector<vector<SumType>> s;
};


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

    int N, K;
    cin >> N >> K;
    vi x(N), y(N);
    vector<char> c(N);

    auto white = vv(int, 2*K, 2*K, 0);
    auto black = white;

    rep(i, N) {
        cin >> x[i] >> y[i] >> c[i];

        int xx = (x[i] / K) % 2 * K + x[i] % K;
        int yy = (y[i] / K) % 2 * K + y[i] % K;
        if (c[i] == 'W')white[xx][yy]++;
        else black[xx][yy]++;
    }

    auto f = [&](deque<int> &xx) {
        while (xx.back() < 2 * K)xx.push_back(min(xx.back() + K, 2 * K));
        while (xx[0] > 0)xx.push_front(max(xx[0] - K, 0));
    };

    int ans = 0;
    Sum2D sw(white), sb(black);
    deque<int> xx;
    deque<int> yy;
    rep(i, K)rep(j, K) {
        int w = 0;
        xx.push_back(i);
        yy.push_back(j);
        f(xx);
        f(yy);

        rep(ii, sz(xx)-1)rep(jj, sz(yy)-1) {
            int col = (ii + jj) % 2;
            auto &sm = col ? sw : sb;
            w += sm.get(xx[ii], yy[jj], xx[ii + 1], yy[jj + 1]);
        }
        xx.clear();
        yy.clear();
        smax(ans, w);
        smax(ans, N - w);
    }
    cout << ans << endl;
}

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


int main()
{
   int a,b,h,m;
   cin>>a>>b>>h>>m;

   double dist, angm, angh, angle;

   angm=6.0*m;
   angh=h*30.0+m/2.0;

   angle=abs(180.0-(angm-angh));

   angle=angle*3.141592653589793238/180.0;

   dist=sqrt(a*a + b*b + 2*a*b*cos(angle)) ;

   cout<<fixed<<setprecision(20)<<dist;

    return 0;
}


Measured memory_bytes: 4264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	deque <char>a;
	for(ll i=0;i<s.size();i++){
		a.push_back(s[i]);
	}
	bool ch=true;
	ll ans=0;
	while(ch){
		if(a.size()==1||a.size()==0){
			
			break;
		}
		ch=false;
		if(a.front()==a.back()){
			ch=true;
			a.pop_front();
			a.pop_back();
		}
		else if(a.front()=='x'){
			ch=true;ans++;
			a.pop_front();
		}
		else if(a.back()=='x'){
			ch=true;ans++;
			a.pop_back();
		}
	}
	if(a.size()==0||a.size()==1){
	cout << ans;
	}
	else{
		cout << "-1";
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 512
N,M=map(int,input().split())
    
if M==0 :
    print(0,0)
    exit()

ACCNT=[False]*N
Asum=0
WACNT=[0]*N

for i in range(M):
    PI,SI=input().split()
    iii=int(PI)-1
    if ACCNT[iii]==False:
        if SI=="WA" :
            WACNT[iii]=WACNT[iii]+1
        elif SI=="AC" :
            ACCNT[iii]=True
            Asum=Asum+1

Wsum=0
for i in range(N):
    if ACCNT[i]==True:
        Wsum=Wsum+WACNT[i]

print(Asum,Wsum)

Measured memory_bytes: 4596
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define E 1e-6
#define INF 0x3f3f3f3f
void open(){freopen("data.txt","r",stdin);}
void out(){freopen("out.txt","w",stdout);}
const int maxn = 101010;
const int MOD = 1e9 + 7;


int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a==b) printf("%d\n",c);
    else if(a==c) printf("%d\n",b);
    else if(b==c) printf("%d\n",a);
}


Measured memory_bytes: 256
program unhappy_hacking
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer :: n, m, i, j
  character(5000) :: s
  integer(8) :: dp(0:5000,0:5000) = 0_8, p = 1_8, t = 500000004_8
  read(*,*) n
  read(*,*) s
  s = trim(adjustl(s))
  m = len_trim(s)
  dp(0,0) = 1_8
  do i = 1, n
    dp(i,0) = mod(dp(i-1,0)+dp(i-1,1),md)
    do j = 1, i-1
      dp(i,j) = mod(2_8*dp(i-1,j-1)+dp(i-1,j+1),md)
    end do
    dp(i,i) = mod(2_8*dp(i-1,i-1),md)
  end do
  do i = 0, 15
    if (btest(m,i)) p = mod(t*p,md)
    t = mod(t*t,md)
  end do
  write(*,'(i0)') mod(dp(n,m)*p,md)
  stop
end program unhappy_hacking

Measured memory_bytes: 194944
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#define dotimes(i, n) for (size_t i = 0; i < n; i++)
using namespace std;

int main(int argc, char const* argv[])
{
    int W, H;
    cin >> W >> H;

    vector<long long> p(W);
    vector<long long> q(H);
    for (auto& pi : p) { cin >> pi; }
    for (auto& qj : q) { cin >> qj; }

    sort(begin(p), end(p));
    sort(begin(q), end(q));

    long long ans = 0;
    int i = 0;
    int j = 0;
    while (i < W || j < H) {
        if (j == H) {
            ans += (H + 1 - j) * p[i];
            i++;
        } else if (i == W) {
            ans += (W + 1 - i) * q[j];
            j++;
        } else if (p[i] <= q[j]) {
            ans += (H + 1 - j) * p[i];
            i++;
        } else {
            ans += (W + 1 - i) * q[j];
            j++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)

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

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}



int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0;i < N;i++){
        cin >> A[i];
    }
    ll X = 1000;
    for(int i = 0;i < N-1;i++){
        int s = A[i];
        int t = A[i+1];
        if(s < t){
            ll k = X/s;
            X %= s;
            X += k*t;
        }
    }
    cout << X << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] ss = s.toCharArray();
		String t = sc.next();
		char[] tt = t.toCharArray();
		int ans = 0;
		for (int i = 0; i <= s.length() - t.length(); i++) {
			// i = スタート地点
			// 先頭比較、0～s-tまで
			int tmp = 0;
			for (int j = 0; j < t.length(); j++) {
				if (ss[i+j] == tt[j]) {
					tmp++;
				}
			}
			if (tmp > ans) {
				ans = tmp;
			}

		}
		System.out.println(t.length() - ans);

	}
	
}


Measured memory_bytes: 35632
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int X,N;
    int[] P;
    private void solve() {
        X = nextInt();
        N = nextInt();

        if (N == 0) {
            out.println(X);
            return;
        }

        P = nextIntArray(N);
        boolean[] no = new boolean[100+2];
        for(int i = 0;i < N;i++) {
            no[P[i]] = true;
        }

        int ans = 0;
        for(int i = 0;i <= 50;i++) {
            if (!no[X - i]) {
                ans = X - i;
                break;
            }

            if (!no[X + i]) {
                ans = X + i;
                break;
            }
        }

        out.println(ans);

    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] x = new int[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextInt();
        }
        return x;
    }

    public long[] nextLongArray(int n) {
        long[] x = new long[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextLong();
        }
        return x;
    }

    public double[] nextDoubleArray(int n) {
        double[] x = new double[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextDouble();
        }
        return x;
    }
}

Measured memory_bytes: 32548
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	for (int i = k + 1; i <= n; i++) {
		ans += (i - k)*(n / i);
		if (n%i >= k) ans += n%i - k + 1;
	}
  if(k==0) ans-=n;
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
class Main{
    public static void main(String[] args){
    BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
    try {
	while(true){
	String st = sc.readLine();
	if(st.equals("-1 -1 -1"))
		break;
	String[] sp = st.split(" ");
	int hours = Integer.valueOf(sp[0]);
	int minutes = Integer.valueOf(sp[1]);
	int seconds = Integer.valueOf(sp[2]);
	int total = hours*60*60+minutes*60+seconds;
	int remains = 120*60-total;
	int remains3 = 120*60*3-total*3;
	System.out.printf("%02d:%02d:%02d",remains/3600,(remains-(remains/3600)*3600)/60,remains%60);
	System.out.println();
	System.out.printf("%02d:%02d:%02d",remains3/3600,(remains3-(remains3/3600)*3600)/60,remains3%60);
	System.out.println();
	}
    }catch(Exception e){
        System.out.println("Error");
    }
    }
}

Measured memory_bytes: 17020
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var (n, m) = (nm[0], nm[1]);
        var roads = new (int A, int B)[m];
        for (int i = 0; i < roads.Length; ++i)
        {
            var r = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            roads[i] = (r[0], r[1]);
        }

        var uf = new UnionFind(n + 1);
        for (int i = 0; i < roads.Length; ++i)
        {
            uf.Unite(roads[i].A, roads[i].B);
        }

        var k = uf.Count - 2;

        Console.WriteLine(k);
    }
}

class UnionFind
{
    int[] nodes;

    public int Count { get; private set; }

    public UnionFind(int size)
    {
        this.nodes = Enumerable.Repeat(-1, size).ToArray();
        Count = size;
    }

    public int Find(int x)
    {
        var p = nodes[x];
        if (p < 0)
        {
            return x;
        }

        return nodes[x] = Find(p);
    }

    public void Unite(int x, int y)
    {
        var p = Find(x);
        var q = Find(y);
        if (p == q)
        {
            return;
        }

        var r = nodes[p];
        var s = nodes[q];
        if (r > s)
        {
            p += q;
            q = p - q;
            p -= q;
        }
        nodes[p] += nodes[q];
        nodes[q] = p;
        Count--;
    }

    public bool Union(int x, int y)
        => Find(x) == Find(y);

    public int GetSize(int x)
        => -nodes[Find(x)];
}


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

int main() {
  int N, a, b;
  cin >> N;
  vector<int>P(N);
  vector<int>Q(N);
  vector<int>R(N);
  for (int i = 0; i < N; i++) {
    cin >> P.at(i);
    Q.at(i) = P.at(i);
  }
  sort(Q.begin(), Q.end());
  bool ans, check = false;
  for (int i = 0; i < N; i++) {
    for (int j = i; j < N; j++) {
      for (int k = 0; k < N; k++) {
        R.at(k) = P.at(k);
      }
      ans = true;
      a = R.at(i);
      b = R.at(j);
      R.at(i) = b;
      R.at(j) = a;
      for (int k = 0; k < N; k++) {
        if (R.at(k) != Q.at(k)) {
          ans = false;
        }
      }
      if (ans) {
        cout << "YES";
        check = true;
        break;
      }
    }
    if (check) {
      break;
    }
  }
  if (!check) {
    cout << "NO";
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <inttypes.h>
#include <string.h>

int main(void) {
	char S[16];
	int len;
	int put;
	uint64_t answer = 0;
	if (scanf("%15s", S) != 1) return 1;
	len = (int)strlen(S);
	for (put = 1 << (len - 1); put < (1 << len); put++) {
		uint64_t current = 0;
		uint64_t current2 = 0;
		int i;
		for (i = 0; i < len; i++) {
			current2 = current2 * 10 + (S[i] - '0');
			if ((put >> i) & 1) {
				current += current2;
				current2 = 0;
			}
		}
		answer += current;
	}
	printf("%" PRIu64 "\n", answer);
	return 0;
}


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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#define IF_DEBUG 0
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;

void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}

const int maxn = 200050;
const int maxm = 2005;
const int P = 1e9+7;

int f[maxm<<1][maxm<<1];
int N, A[maxn], B[maxn], Fac[maxn], Ans;

int inv(int a)
{
	int ans = 1, b = P-2;
	while(b)
	{
		if(b&1) ans = (1ll*ans*a)%P;
		b >>= 1; a = (1ll*a*a)%P;
	}
	return ans;
}
int C(int n,int m)
{
	return (((1ll*Fac[n]*inv(Fac[m]))%P)*inv(Fac[n-m]))%P;
}
int main()
{
	sf("%d",&N);
	fo(i,1,N) sf("%d%d",&A[i],&B[i]);
	fo(i,1,N) f[-A[i]+maxm][-B[i]+maxm] ++;
	fo(i,-2000,2000) fo(j,-2000,2000) 
		f[i+maxm][j+maxm] = (1ll*f[i+maxm][j+maxm]+f[i-1+maxm][j+maxm]+f[i+maxm][j-1+maxm])%P;
	fo(i,1,N) Ans = (1ll*Ans + f[A[i]+maxm][B[i]+maxm])%P;
	Fac[0] = 1; fo(i,1,maxn-1) Fac[i] = (1ll*Fac[i-1]*i)%P;
	fo(i,1,N) Ans = ((1ll*Ans - C(A[i]*2+B[i]*2,A[i]*2))%P+P)%P;
	Ans = 1ll*Ans*inv(2)%P;
	pf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 65280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        
        BufferedReader std = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(std.readLine());
        String str = std.readLine();
        String[] strs = str.split(" ");
        
        for(int i = strs.length-1; i >= 0; i--){
            if(i != 0){
                System.out.print(strs[i] + " ");
            } else {
                System.out.print(strs[i]);
            }
        }
        System.out.println();
    
    }

}

Measured memory_bytes: 24180
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

long long a, b;
double ans;
long long nearIntPos;

int main()
{
	scanf("%lld %lld", &a, &b);
	ans = ceil(a + b) / 2;
	// printf("%lf\n", ans);
	nearIntPos = ceil(ans); 
	printf("%lld", nearIntPos);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
//
//  main.c
//  procon
//
//  Created by L on 2017. 10. 17..
//  Copyright © 2017년 L. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    
    if (b-a == c-b) printf("YES");
    else printf("NO");
    
    
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>

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

int main(){
  double t,x;
  cin >> t >> x;;
  cout << fixed << setprecision(10) << t/x << endl;
}


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

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

    // solve
    int ans = 0;
    bool flag = true;
    while (flag) {
        for (int i = 0; i < A.size(); ++i) {
            if (A[i] % 2 != 0) flag = false;
        }
        for (int i = 0; i < A.size(); ++i) {
            A[i] /= 2;
        }
        if (flag) ans++;
    }

    // output
    cout << ans << endl;

    return 0;
}


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

using namespace std;

int getAns(vector<int> arr,int n,int k)
{
    vector<int> cost(n,INT_MAX);
    cost[0] = -1;
    for(int i = 1;i <= k;i++)
    {
        cost[i] = abs(arr[i]-arr[0]);
    }
    for(int i = k+1;i < n;i++)
    {
        int j = i-k;
        while(j < i)
        {
            cost[i] = min(cost[i],cost[j]+abs(arr[j]-arr[i]));
            j++;
        }
    }
    return cost[n-1];
}

int main()
{
    std::ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    vector<int> arr(n);
    for(int i = 0;i < n;i++)
        cin >> arr[i];
    if(n <= k)
    {
        cout << abs(arr[0]-arr[n-1]) << endl;
    }
    else
    {
        int ans = getAns(arr,n,k);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100010
#define INF 10000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
    int r;
    IN(r);
    OUT(3*r*r);
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = input()
words = ('dream', 'dreamer', 'erase', 'eraser')

while True:
    if S == '':
        print("YES")
        break

    for word in words:
        if S.endswith(word):
            S = S[:-len(word)]
            break
    else:
        print("NO")
        break


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxN = 1e5+7;
const int maxV = 90010;
//const int INF = 1e9+9;
//const ll INF = (1ll)<<60;
const int INF = 2e9+9;
const ull MOD = 16769023;
const ull MOD1 = 1125899839733759;
int n,k;


ll a[maxN];
ll b[maxN];
int main()
{
	scanf("%d%d",&n,&k);
	if(n<k)
	{
		puts("0");
	}
	else
	{
		puts("10");
	}
	return 0;
}


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

using namespace std;

int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  int l = 0;
  int r = 0;
  int flip = 0;
  int answer = 0;

  while (r < N && S[r] == '1') r++;
  answer = max(answer, r - l);

  while (flip < K && r < N) {
    while (r < N && S[r] == '0') r++;
    while (r < N && S[r] == '1') r++;
    flip++;
    answer = max(answer, r - l);
  }

  while (r < N) {
    while (r < N && S[r] == '0') r++;
    while (r < N && S[r] == '1') r++;
    while (l < N && S[l] == '1') l++;
    while (l < N && S[l] == '0') l++;
    answer = max(answer, r - l);
  }

  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int MOD = 1000000007;
const int N = 500005;

int n, k, tab[N], i, res, act;

int inverse(int a, int n = MOD - 2) {
    int r = 1;
    while (n) {
        if (n % 2) r = (r * 1LL * a) % MOD;
        a = (a * 1LL * a) % MOD;
        n >>= 1;
    }
    return r;
}

int main() {
scanf("%d %d", &n, &k);
for (i=1;i<=n;i++) scanf("%d", &tab[i]);
sort(tab + 1, tab + n + 1);
act = 1;
for (i=k;i<=n;i++) {
	res = (tab[i] * 1LL * act + res) % MOD;
	res = (-tab[n - i + 1] * 1LL * act + res) % MOD;
	if (i < n) {
		act = (act * 1LL * i) % MOD;
		act = (act * 1LL * inverse(i - k + 1)) % MOD;
	}
}
if (res < 0) res += MOD;
printf("%d\n", res);
}

Measured memory_bytes: 640
N, M = list(map(int, input().split()))
A = []
B = []
for _ in range(M):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)

class UnionFind:
    def __init__(self, n: int) -> None:
        #マイナスならルートでその深さを表す。プラスならルートのノードを指す。
        self.nodes = [-1]*n
 
    def find_root(self, x: int) -> int:
        if self.nodes[x] < 0:
            return x
        else:
            self.nodes[x] = self.find_root(self.nodes[x])
            return self.nodes[x]
 
    def unite(self, x: int, y: int) -> None:
        x, y = self.find_root(x), self.find_root(y)
        #浅い方につなぐ
        if (x != y):
            if (x < y):
                self.nodes[y] += self.nodes[x]
                self.nodes[x] = y
            else:
                self.nodes[x] += self.nodes[y]
                self.nodes[y] = x
    def get_rank(self, x: int) -> int:
        return (self.nodes[x])

u = UnionFind(N+1)
p = N * (N - 1) // 2
ans = [p]
for a, b in zip(A[1:][::-1],B[1:][::-1]):
    pa = u.find_root(a)
    pb = u.find_root(b)
    if pa != pb:
        p -= u.get_rank(pa) * u.get_rank(pb)
        u.unite(pa, pb)
    ans.append(p)
print(*ans[::-1], sep="\n")


Measured memory_bytes: 19112