akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {
	
	
	long long int n, k;
	cin >> n >> k;
	long long int a = 0;
	if (k % 2) {
		a = n / k;
		cout << a*a*a << endl;
	}
	else {
		a = n / k;
		long long int b = n/k;
	//	b /= k;
		if (n%k >= (k / 2))b++;
		cout << a*a*a+ b*b*b << endl;
	}

	return 0;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

"""
参考：http://drken1215.hatenablog.com/entry/2018/09/23/224100
　　　http://tutuz.hateblo.jp/entry/2018/09/24/121248
・素因数分解と重複組み合わせ
・毎回階乗やると死ぬから階乗と逆元のテーブル作る(忘れてた)
"""

from collections import defaultdict
from math import sqrt

MOD = 10 ** 9 + 7

def fact_prime(num):
    d = defaultdict(int)
    # 終点はルート切り捨て+1
    end = int(sqrt(num)) + 1
    for i in range(2, end+1):
        cnt = 0
        # 素因数分解：小さい方から割れるだけ割って素数をカウント
        while num % i == 0:
            num //= i
            d[i] += 1
        # 1まで来たら終了
        if num == 1:
            break
    # 最後までそのまま来たやつはnumが素数(ただし1^1は1^0なので数に入れない)
    if num != 1:
        d[num] += 1
    return d

# とりあえずv+N-1が収まればいいはず
MAX = 10 ** 5 * 2
# 予め組み合わせ計算に必要な階乗と逆元のテーブルを作っておく
factorial = [1] * (MAX)
factorial[0] = factorial[1] = 1
for i in range(2, MAX):
    factorial[i] = factorial[i-1] * i % MOD

inverse = [1] * (MAX)
# powに第三引数入れると冪乗のmod付計算を高速にやってくれる
inverse[MAX-1] = pow(factorial[MAX-1], MOD-2, MOD)
for i in range(MAX-2, 0, -1):
    # 最後から戻っていくこのループならH+W回powするより処理が速い
    inverse[i] = inverse[i+1] * (i+1) % MOD

# 組み合わせの数
def nCr(n, r):
    # 10C7 = 10C3
    r = min(r, n-r)
    # 分子の計算
    numerator = factorial[n]
    # 分母の計算
    denominator = inverse[r] * inverse[n-r] % MOD
    return numerator * denominator % MOD

N, M = map(int, input().split())

# d = fact_prime(M)
# print(d)
ans = 1
for k, v in fact_prime(M).items():
    # 重複組み合わせ
    # v個のkとN-1個の仕切りから、v個を並べる(v+N-1個のマスからv個を選び出す組み合わせ)
    ans = (ans * nCr(v+N-1, v)) % MOD
print(ans)


Measured memory_bytes: 19188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N;cin >> N;
    int A[N];
    vector<pair<int,int>> X[N];
    REP(i,N){
        cin >> A[i];
            REP(j,A[i]){
                int x,y;cin >> x >> y;x--;
                X[i].pb({x,y});
            }
    }
    int ans = 0;
    bool flag = 1;
    REP(bit,(2 << (N-1))){
        flag = 1;
        REP(i,N){
            if(bit & (1 << i)){
                REP(j,A[i]){
                    if(bit & (1 << X[i][j].first)){
                        if(1 != X[i][j].second){
                            flag = 0;
                            break;
                        }
                        continue;
                    }
                    else{
                        if(0 == X[i][j].second) continue;
                        flag = 0;
                      break;
                    }
                }
            }
            if(flag && i == N -1) ans = max(ans,__builtin_popcount(bit));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import datetime

weekdays = [
    'Monday',
    'Tuesday',
    'Wednesday',
    'Thursday',
    'Friday',
    'Saturday',
    'Sunday'
]

while True:
    m,d = [int(i) for i in input().split()]
    if not(m or d):
        break
    print(weekdays[datetime.date(2004, m, d).weekday()])

Measured memory_bytes: 6044
N, M = map(int, input().split())
cake = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for bit in range(8):
    u = 1 if (bit >> 0) & 1 else -1
    v = 1 if (bit >> 1) & 1 else -1
    w = 1 if (bit >> 2) & 1 else -1
    A = []
    for (x, y, z) in cake:
        A.append(x * u + y * v + z * w)
    A.sort(reverse=True)
    ans = max(ans, sum(A[:M]))

print(ans)


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

const int MaxRC=1e6;
const int INF=1<<30;
struct DATA{
	int x, y, dir, stp;
	DATA(int x=0,int y=0,int d=0,int s=0):x(x),y(y),dir(d),stp(s){}
} st, ed;
int main(){
	int R, C, K, k, buff;
	while(scanf("%d %d %d\n",&R,&C,&K)!=EOF){
		scanf("%d %d %d %d\n",&st.x,&st.y,&ed.x,&ed.y);
		st.x--, st.y--, ed.x--, ed.y--;
		
		vector<vector<char>> mat(R, vector<char>(C));
		for(int i=0;i<R;i++,getchar())
			for(int j=0;j<C;j++)
				scanf("%c",&mat[i][j]);
		vector<vector<int>> step(R, vector<int>(C,INF));
		
		queue<DATA> Q;
		Q.push(DATA(st.x,st.y,0,0));
		Q.push(DATA(st.x,st.y,1,0));
		step[st.x][st.y]=0;
		while(Q.empty()==0){
			DATA now=Q.front(); Q.pop();
			if(now.stp!=step[now.x][now.y]) continue;
			if(now.dir){ //
				buff=k=1;
				for(int frw=now.x+1; frw<R and mat[frw][now.y]=='.'; frw++){
					if(step[frw][now.y]>now.stp+k)
						step[frw][now.y]=now.stp+k,
						Q.push(DATA(frw,now.y,0,now.stp+k));
					if(buff==K) buff=1, k++; else buff++;
				}
				buff=k=1;
				for(int bck=now.x-1; bck>=0 and mat[bck][now.y]=='.'; bck--){
					if(step[bck][now.y]>now.stp+k)
						step[bck][now.y]=now.stp+k,
						Q.push(DATA(bck,now.y,0,now.stp+k));
					if(buff==K) buff=1, k++; else buff++;
				}
			}else{
				buff=k=1;
				for(int frw=now.y+1; frw<C and mat[now.x][frw]=='.'; frw++){
					if(step[now.x][frw]>now.stp+k)
						step[now.x][frw]=now.stp+k,
						Q.push(DATA(now.x,frw,1,now.stp+k));
					if(buff==K) buff=1, k++; else buff++;
				}
				buff=k=1;
				for(int bck=now.y-1; bck>=0 and mat[now.x][bck]=='.'; bck--){
					if(step[now.x][bck]>now.stp+k)
						step[now.x][bck]=now.stp+k,
						Q.push(DATA(now.x,bck,1,now.stp+k));
					if(buff==K) buff=1, k++; else buff++;
				}
			}
		}
		printf("%d\n",(step[ed.x][ed.y]==INF)? -1: step[ed.x][ed.y]);
	}
}




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

int main(){
    int a,b,k; cin>>a>>b>>k;
    int count=0,ans;

    for(int i=min(a,b); i>=1; i--){
        if(a % i == 0 & b % i == 0)count++;
        if(count == k){
            ans = i;        
            break;
        }

    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << (x) << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

typedef pair<ll, pair<string, int>> S;

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

	int n;
	cin >> n;
	vector<string> s(n); vector<ll> c(n);
	vector<string> revs(n);
	rep(i, n) cin >> s[i] >> c[i];
	map<string, ll> mp;
	priority_queue<S, vector<S>, greater<S>> que;
	que.push({ 0,{"",0} });
	que.push({ 0,{"",1} });
	int f = 0;
	while (!que.empty()) {
		S p = que.top(); que.pop();
		ll cost = p.first; string now = p.second.first; int mode = p.second.second;
		int len = now.size();
		if (cost != 0) {
			bool ok = true;
			rep(i, len) if (now[i] != now[len - 1 - i]) ok = false;
			if (ok) {
				cout << cost << '\n';
				return 0;
			}
		}
		f++;
		if (f > 1000000) break;
		if (cost > mp[now]) continue;
		rep(i, n) {
			int sz = s[i].size();
			string tmp = s[i];
			if (mode == 0) reverse(all(tmp));
			if (now.size() >= sz && now.substr(0, sz) == tmp) {
				string rem = now.substr(sz);
				mp[rem] = cost + c[i];
				que.push({ cost + c[i],{rem,mode} });
			}
			if (tmp.substr(0, len) == now) {
				string rem = tmp.substr(len);
				mp[rem] = cost + c[i];
				que.push({ cost + c[i],{rem,mode ^ 1} });
			}
		}
	}
	cout << "-1\n";
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>

using ll = long long;
using namespace std;
constexpr ll inf = 1e15;

#define MAX_N 1000

constexpr int MAX = 10000;
constexpr int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// dp[i][j] := 最大のグループ人数がj人であるとき、i人をグループ分けする場合の数
ll dp[MAX_N+1][MAX_N+1] = {0};

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

    int N, A, B, C, D;
    cin>>N>>A>>B>>C>>D;

    for (int i = 0; i <= B; i++) dp[0][i] = 1;

    COMinit();
    
    for (int n = 1; n <= N; n++) {
        for (int i = A; i <= B; i++) {
            ll comb = 1;
            dp[n][i] = dp[n][i-1];
            for (int j = 1; j < C; j++) comb = (((comb * COM(n - i * (j - 1), i)) % MOD) * inv[j]) % MOD;
            for (int j = C; j <= min(D, (n/i)); j++) {
                 ll F = i * j;
                 comb = (((comb * COM(n - i * (j - 1), i)) % MOD) * inv[j]) % MOD;
                 dp[n][i] = (dp[n][i] + (dp[n - F][i - 1] * comb % MOD)) % MOD;
            }
        }
    }

    cout<<dp[N][B]<<endl;

    return 0;
}

Measured memory_bytes: 8320
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

count = 0
for i in range(n):
    count += min(a[i], b[i])
    count += min(a[i + 1], max(b[i] - a[i], 0))
    a[i + 1] -= min(a[i + 1], max(b[i] - a[i], 0))
print(count)

Measured memory_bytes: 18476
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main() {
	int a[1000000];
	bool a2[1000000];
	int n;
	while (cin >> n&&n != 0) {
		int c = 0;
		for (int i = 0; i < n; i++) {
			int x;
			cin >> x;
			bool l = x == 1 ? 1 : 0;
			if (c == 0) {
				a[0] = 1;
				a2[0] = l;
				c++;
			}
			else if (i % 2 == 0) {
				if (a2[c - 1] == l) {
					a[c - 1]++;
				}
				else {
					a[c] = 1;
					a2[c] = l;
					c++;
				}
			}
			else {
				if (a2[c - 1] == l) {
					a[c - 1]++;
				}
				else {
					if (c >= 2) {
						a[c - 2] += a[c - 1];
						a[c - 2]++;
						c--;
					}
					else {
						a[c - 1]++;
						a2[c-1] = l;
					}
				}
			}
		}
		int sum = 0;
		for (int i = 0; i < c; i++) {
			if (!a2[i]) {
				sum += a[i];
			}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 2976
n,a,b=map(int,input().split())
#2**n-nCa-nCb-1
P=10**9+7
class Combination:
    def __init__(self,N,P):
        fact=[];ifact=[];fact=[1]*(N+1);ifact=[0]*(N+1)
        for i in range(1,N):
            fact[i+1]=(fact[i]*(i+1))%P
        ifact[-1]=pow(fact[-1],P-2,P)
        for i in range(N,0,-1):
            ifact[i-1]=(ifact[i]*i)%P
        self.fact=fact;self.ifact=ifact;self.P=P
    def comb(self,n,k):
        return (self.fact[n]*self.ifact[k]*self.ifact[n-k])%self.P
C=Combination(3*10**5,P)
A=1
for i in range(1,a+1):
    A*=n-i+1
    A%=P
A*=C.ifact[a]
A%=P
B=1
for i in range(1,b+1):
    B*=n-i+1
    B%=P
B*=C.ifact[b]
B%=P
print((pow(2,n,P)-A-B-1)%P)

Measured memory_bytes: 43760
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//FUNCTION
void DFS(string str,int T,int depth,vector<int> & data)
{
  str +=char(T+'0');
  data.push_back(stol(str));
  if(depth == 11) return;
  for (int i = -1; i < 2; i++)
  {
    int nn = T + i;
    if(nn<0 || nn>9)continue;
    DFS(str,T+i,depth+1,data);
  }
  
  return;
}
void solve(void)
{
  vector<int> data;
  for (int i = 1; i < 10; i++)
  {
    DFS("",i,1,data);
  }
  int K;cin>>K;
  sort(ALL(data));
  cout<<data[K-1]<<endl;
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 10604
import bisect
n,a,b,c=map(int,input().split())
l=[int(input()) for x in range(n)]
l.sort()
total=4**n
ans=999999999
for i in range(total):
    fora=[]
    forb=[]
    forc=[]
    nonused=[]
    temp_i = i
    for j in range(n):
        temp=temp_i%4
        if(temp==0):
            fora.append(l[j])
        elif(temp==1):
            forb.append(l[j])
        elif(temp==2):
            forc.append(l[j])
        else:
            nonused.append(l[j])
        temp_i = temp_i // 4
    if(len(fora)==0 or len(forb)==0 or len(forc)==0):
        continue
    else:
        mp=0
        mp+=10*(len(fora)-1)
        len_fora=sum(fora)
        mp+=abs(a-len_fora)

        mp+=10*(len(forb)-1)
        len_forb=sum(forb)
        mp+=abs(b-len_forb)

        mp+=10*(len(forc)-1)
        len_forc=sum(forc)
        mp+=abs(c-len_forc)

        if(ans > mp):
            ans = mp
print(ans)

Measured memory_bytes: 3188
from collections import Counter
import numpy as np

N = int(input())
a = list(map(int, input().split()))
l = [0] * ((10 ** 5) + 5)
c = Counter(a)

for k, v in c.items():
    l[k] = v

c_l = np.cumsum(l)

max_n = c_l[2]
for i in range(3, len(l)):
    max_n = max(max_n, c_l[i] - c_l[i - 3])
print(max_n)


Measured memory_bytes: 23488
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
	int h, w;
	cin >> h >> w;
	vector<string> vs;
	for (int i = 0; i < h; i++) {
		string s;
		cin >> s;
		vs.push_back(s);
	}
	
	unordered_map<int, unordered_map<int, int>> um;
	vector<pair<int, int>> v1, v2;
	vector<pair<int, int>> dir = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, -1), make_pair(0, 1)};
	int res = 0;
	for (int i = 0; i < h * w; i++) {
		um.clear();
		v1.clear();
		if (vs[i / w][i % w] == '#') continue;
		v1.push_back(make_pair(i / w, i % w));
		um[v1[0].first][v1[0].second] = 1;
		int r = 0;
		while (v1.size() > 0) {
			v2.clear();
			for (auto node : v1) {
				for (auto p : dir) {
					int x = node.first + p.first, y = node.second + p.second;
					if (x < 0 || y < 0 || x >= h || y >= w) continue;
					if (vs[x][y] == '#' || um[x][y] == 1) continue;
					v2.push_back(make_pair(x, y));
					um[x][y] = 1;
				}
			}
			v1 = v2;
			r++;
		}
		res = max(res, r - 1);
	}
	cout << res  << endl;
}









Measured memory_bytes: 256
#=
B:
- Julia version:0.5.2
- Author: abap
- Date: 2020-01-12
=#
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
a,b = parse.(split(readline()))

if a<b
    for i in 1:b
    print(a)
    end
else
    for i in 1:a
    print(b)
    end
end

println("")

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;


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

  if(n%2 == 0) cout << 0.5 << endl;
  else         cout << 1.0*(n/2+1) / n << endl;
  
  


  return 0;
}


Measured memory_bytes: 256
class WeightedUnionFindTree:
    """Disjoint-Set Data Structure with weight

    complexity:
        - init: O(n)
        - find, unite, same: O(alpha(n))
    """

    def __init__(self, n_nodes):
        self.par = [i for i in range(n_nodes)]  # parent
        self.rank = [0] * n_nodes  # depth of tree
        self.weights = [0] * n_nodes

    def find(self, x):
        if self.par[x] == x:
            return x
        root = self.find(self.par[x])
        self.weights[x] += self.weights[self.par[x]]
        self.par[x] = root
        return root

    def unite(self, x, y, weight=0):
        root_x, root_y = self.find(x), self.find(y)
        if root_x == root_y:
            return
        if self.rank[root_x] < self.rank[root_y]:
            self.par[root_x] = root_y
            self.weights[root_x] = weight - self.weights[x] + self.weights[y]
        else:
            self.par[root_y] = root_x
            self.weights[root_y] = -weight - self.weights[y] + self.weights[x]
            if self.rank[root_x] == self.rank[root_y]:
                self.rank[root_x] += 1

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

    def diff(self, x, y):
        return self.weights[x] - self.weights[y]


N, M = map(int, input().split())
uft = WeightedUnionFindTree(N)

for _ in range(M):
    l, r, d = map(int, input().split())
    l, r = l-1, r-1
    if not uft.is_same(l, r):
        uft.unite(l, r, d)
    else:
        if uft.diff(l, r) != d:
            print("No")
            quit()
else:
    print("Yes")


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

using namespace std;
typedef long long LL;

const int N=2e5+10,M=2010,Mod=1e9+7;

int n,A[N],B[N],f[M<<1][M<<1],fact[M<<2],inv[M<<2];

void Init()
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d%d",&A[i],&B[i]);
}

LL Calc(int m,int n)
{
	if (n==0) { if (m==0) return 1ll; else return 0ll; }
	return 1ll*fact[n]*inv[m]%Mod*inv[n-m]%Mod;
}

void Solve()
{
	LL ans=0;
	for (int i=1;i<=n;++i) f[A[i]+M][B[i]+M]++;
	for (int i=2000+M;i>=-2000+M;--i)
		for (int j=2000+M;j>=-2000+M;--j)
		{
			f[i][j]=(f[i+1][j]+f[i][j+1]+f[i][j])%Mod;
//			if (f[i][j]) 
//				printf("%d %d %d\n",i-M,j-M,f[i][j]);
		}
	for (int i=1;i<=n;++i) 
		ans=(ans+f[M-A[i]][M-B[i]])%Mod;
	
	fact[0]=fact[1]=1; for (int i=2;i<=(M<<2);++i) fact[i]=1ll*fact[i-1]*i%Mod;
	inv[0]=inv[1]=1;   for (int i=2;i<=(M<<2);++i) inv[i]=1ll*(Mod-Mod/i)*inv[Mod%i]%Mod;
	for (int i=1;i<=(M<<2);++i) inv[i]=1ll*inv[i-1]*inv[i]%Mod;
	for (int i=1;i<=n;++i) ans=(ans+Mod-Calc(A[i]<<1,(A[i]+B[i])<<1))%Mod;//,printf("%d\n",Calc(A[i]<<1,(A[i]+B[i])<<1));
	printf("%lld\n",ans*inv[2]%Mod);
}

int main()
{
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 64896
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	string s, t;
	cin >> s >>t;
	for (int i = 0; i < s.size();i++) {
		if (s==t) {
			cout << "Yes" << endl;
			return 0;
		}
		s = s.back() + s.substr(0, s.size() - 1);
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [0]*N
B = [0]*N

for i in range(N):
    A[i], B[i] = map(int, input().split())

A = sorted(A)
B = sorted(B)

if N % 2 == 1:
    print(B[(N+1)//2-1] - A[(N+1)//2-1] + 1)
else:
    b = B[N//2-1] + B[N//2]
    a = A[N//2-1] + A[N//2]
    print(b-a+1)

Measured memory_bytes: 26908
#include <iostream>
#include <string>
using namespace std;
int main() {
	string s;
	cin >> s;
	int curacnt = 0;
	long long totmoves = 0;
	int curind = 0;
	while (curind < s.length() - 1) {
		if (s[curind] == 'A')
			curacnt++;
		else if (s[curind] == 'B' && s[curind + 1] == 'C') {
			curind++;
			totmoves += curacnt;
		} else {
			curacnt = 0;
		}
		curind++;
	}
	cout << totmoves << '\n';
}

Measured memory_bytes: 640
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

template <class T, class U> inline void smax(T &a, U b) { a = a > b ? a : b; }
template <class T, class U> inline void smin(T &a, U b) { a = a < b ? a : b; }

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  for(int i = 0; i < h; i++) cin >> s[i];
  ll ans = 1e9;
  for(int t = 0; t < 1 << (h - 1); t++) {
    ll res = __builtin_popcount(t);
    int cnt[10] = {};
    for(int j = 0; j < w; j++) {
      int g = 0;
      int cnt0[10] = {};
      for(int i = 0; i < h; i++) {
        cnt0[g] += s[i][j] == '1';
        if(t & (1 << i)) g++;
      }
      int cut = 0;
      for(int u = 0; u < 10; u++) {
        if(cnt0[u] > k) res = 1e9;
        if(cnt[u] + cnt0[u] > k) {
          res++, cut = 1;
          break;
        }
      }
      if(cut) {
        for(int u = 0; u < 10; u++) {
          cnt[u] = cnt0[u];
        }
      } else {
        for(int u = 0; u < 10; u++) {
          cnt[u] += cnt0[u];
        }
      }
    }
    smin(ans, res);
  }
  cout << ans << endl;
  return 0;
}


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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int A, B;
    cin >> A >> B;
    if(A - B*2 >= 0) cout << A - (B * 2) << endl;
    else cout << 0 << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

vector<vector<int>> a;

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

    while(i < n){
        vector<int> tmp;
        while (true){
            if(s[i] == 'A') tmp.push_back(1), i++;
            else if (i < n-1 && s[i] == 'B' && s[i+1] == 'C') tmp.push_back(0), i+=2;
            else{
                i++;
                break;
            }
        }
        if (!tmp.empty()) a.push_back(tmp);
    }

    ll m = a.size();
    ll ans = 0;
    rep(i, m){
        ll cnt = 0, dist = 0;
        rep(j, a[i].size()){
            if (a[i][j] == 0) cnt++, dist += j;
        }
        if (cnt < a[i].size()) ans += dist - cnt * (cnt - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3128
#include <stdio.h>

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

    int a;
    int b;
    int c;
    
    scanf("%d %d %d",&a,&b,&c);
    if (a<b&&b<c) {
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    
    return 0;
    
}

Measured memory_bytes: 580
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::string s;
    cin >> s;
    int64_t res   = 0;
    int64_t count = 0;
    for (auto x : s) {
        if (x == 'B') {
            count++;
        } else {
            res += count;
        }
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=200020;

int main() {
  string s;
  ll N;
  cin>>N>>s;
  ll ans=MAX,cnt=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='.'){
      cnt++;
    }
  }
  ans=cnt;
  for(int i=0;i<s.size();i++){
    if(s[i]=='.'){
      cnt--;
    }
    if(s[i]=='#'){
      cnt++;
    }
    ans=min(ans,cnt);
  }
  cout<<ans;
  
}


Measured memory_bytes: 644
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


	string S, T;
	cin >> S >> T;

	cout << T << S << endl;


	Would you please return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();

        final Map<Integer, List<Node>> tree = new HashMap<>();
        for (int i = 0; i < n - 1; i++) {
            final int a = scanner.nextInt();
            final int b = scanner.nextInt();
            final int c = scanner.nextInt();
            tree.computeIfAbsent(a, v -> new ArrayList<>()).add(new Node(b, c));
            tree.computeIfAbsent(b, v -> new ArrayList<>()).add(new Node(a, c));
        }

        final int q = scanner.nextInt();
        final int k = scanner.nextInt();

        final long[] distances = new long[n + 1];
        distances[k] = Long.MAX_VALUE;
        recursive(distances, tree, k, 0);

        for (int i = 0; i < q; i++) {
            final int x = scanner.nextInt();
            final int y = scanner.nextInt();
            System.out.println(distances[x] + distances[y]);
        }
    }

    private static void recursive(final long[] distances, final Map<Integer, List<Node>> tree, final int currentNode, final long sumDistance) {
        final List<Node> destinations = tree.get(currentNode);
        for (final Node destination : destinations) {
            if (distances[destination.label] != 0) {
                continue;
            }

            distances[destination.label] = sumDistance + destination.distance;
            recursive(distances, tree, destination.label, sumDistance + destination.distance);
        }
    }

    static class Node {
        int label;
        long distance;

        Node(final int label, final int distance) {
            this.label = label;
            this.distance = distance;
        }
    }
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X;
    cin >> X;
    REP(i, 100) {
        ll t = 400 + 200 * i;
        if (t <= X && X < t + 200) {
            cout << 8 - i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
#include<numeric>
using namespace std;

int INF = 1e9 + 7;

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

int main() {
	int n;
	cin >> n;
	string s;
	ll m = 0, a = 0, r = 0, c = 0, h = 0;
	for (int i = 1; i <= n; i++) {
		cin >> s;
		if (s[0] == 'M') m++;
		if (s[0] == 'A') a++;
		if (s[0] == 'R') r++;
		if (s[0] == 'C') c++;
		if (s[0] == 'H') h++;
	}
	cout << m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
// using ll = long long;
// using vi = vector<int>;
// using vvi = vector<vi>;
// using vl = vector<long long>;
// using vvl = vector<vl>;
// using vs = vector<string>;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

int kaijo (int a, int result) {
  if (a == 0) {
    return result;
  } else {
    return kaijo(a-1, result * a);
  }
}

int kaijo(int a) {
  return kaijo(a,1);
}

ll kaijo_ll (ll a, ll result) {
  if (a == 0) {
    return result;
  } else {
    return kaijo_ll(a-1, result * a);
  }
}

ll kaijo_ll(ll a) {
  return kaijo_ll(a,1);
}

int main () {
  int n;
  cin >> n;
  std::vector<int> v(n);
  // double result=0;
  double bunbo = pow(2,n-1), bunshi = 0;
  rep(i,n) cin >> v[i];
  VSORT(v);
  for (int i = n-1; i >= 1; i--) {
    bunshi += v[i] * pow(2, i-1);
  }
  bunshi += v[0];
  double result = bunshi/bunbo;
  printf("%.20lf\n", result);
}


Measured memory_bytes: 512
import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
	private static BufferedReader br = null;
	
	public static void main(String[] args) {
		int n = Integer.parseInt(read(1)[0]);
		
		if (n == 1) {
			System.out.println("Hello World");
		} else {
			String[] strs = read(2);
			System.out.println(Integer.parseInt(strs[0]) + Integer.parseInt(strs[1]));
		}
	}
	
	private static String[] read(int len) {
		List<String> strList = new ArrayList<>();
		
		try {
			if (br == null) {
				br = new BufferedReader(new InputStreamReader(System.in));
			}
			
			for (int i = 0; i < len; i++) {
				strList.add(br.readLine());
			}
		} catch (IOException e) {
		}
		
		return strList.toArray(new String[0]);
	}
	
	private static void close() {
		try {
			if (br != null) {
				br.close();
			}
		} catch (IOException e) {
		}
	}
}


Measured memory_bytes: 21204
#include<stdio.h>
#define N 100000

typedef struct{
  int parent;
  int left;
  int right;
  int depth;
}node;

node T[N];

int main(){
  int n, i, j;
  int id, k, c, p;

  scanf("%d\n",&n);
  for(i = 0 ; i < n ; i++){
    T[i].parent = -1;
    T[i].left = -1;
    T[i].right = -1;
    T[i].depth = 0;
  }

  for(i = 0 ; i < n ; i++){
    scanf("%d%d", &id,&k);
    
    for(j = 0 ; j < k ; j++){
      scanf("%d",&c);
      if( j == 0 ){
	T[id].left = c;
	T[c].parent = id;
      }
      else{
	T[p].right = c;
	T[c].parent = id;
      }
      p = c;
    }
  }
  
  for(i = 0 ; i < n ; i++){
    j = i;
    while(1){
      p = T[j].parent;
      if(p == -1) break;
      j = p;
      T[i].depth++;
    }
 
    printf("node %d: parent = %d, depth = %d,",i, T[i].parent, T[i].depth);
    if(T[i].parent == -1){
      printf(" root, [");
      if( (p = T[i].left) != -1) printf("%d",T[i].left);
 
      if( p != -1){
	while(T[p].right != -1){
          p = T[p].right;
          printf(", %d",p);
        }
      }
      printf("]\n");
    }
    else if(T[i].left != -1){
      printf(" internal node, [");
 
      if( (p = T[i].left) != -1) printf("%d",T[i].left);
 
      while(T[p].right != -1){
	p = T[p].right;
	printf(", %d",p);
      }
      printf("]\n");
    }
    else{
      printf(" leaf, []\n");
    }
  }
  return 0;
}

Measured memory_bytes: 2172
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    string s;
    cin >> s;
    if(s[0] == s[2]){
        output("Yes");
    }
    else output("No");
    
    return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;

public class Main {

    public static void main(String args[]) throws Exception
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long answer =1;
        int modulo = 1000000007;

      //  HashMap<Integer,Integer> map = new HashMap<>();

        for(int i=2;i<=n;i++){
            if(isPrime(i)){
                answer *= (calFactors(n,i)+1);
                if(answer>modulo){
                    answer = answer%modulo;
                }
            }
        }


        System.out.print(answer);

        sc.close();
    }

    private static boolean isPrime(int x){
        for(int i=2;i<x;i++){
            if(x%i==0) return false;
        }
        return true;
    }

    private static int calFactors(int n,int base){
        int ret = 0;
        int tmp = base;
        while(tmp<=n) {
            ret +=  Math.floor( n / tmp);
            tmp *=base;
        }

        return ret;
    }

}

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

int main() {
	string s; cin >> s;
	if (s[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}
	bool cFlag = false;
	for (int i = 1; i < s.size(); i++) {
		if (2 <= i && i <= s.size() - 2 && s[i] == 'C') {
			if (cFlag) {
				cout << "WA" << endl;
				return 0;
			}
			cFlag = true;
		}
		if (s[i] != 'C' && s[i] - 'a' < 0) {
			cout << "WA" << endl;
			return 0;
		}
	}
	cout << (cFlag ? "AC" : "WA") << endl;

	return 0;
}

Measured memory_bytes: 256
n, m, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
max = 0

1.upto(n - 1) { |i| a[i] += a[i - 1] }
1.upto(m - 1) { |i| b[i] += b[i - 1] }
a.unshift(0)
b.unshift(0)

a_idx = a.bsearch_index { |e| e > k }
a_idx = a_idx ? a_idx - 1 : n

0.upto(a_idx) do |i|
  rest = k - a[i]
  b_idx = b.bsearch_index { |e| e > rest }
  b_idx = b_idx ? b_idx - 1 : m

  max = [i + b_idx, max].max
end

puts max

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n, x;
    cin >> n >> x;
    vector<int> v(n);
    rep(i, n){
        cin >> v[i];
    }
    v.push_back(x);
    sort(all(v));
    int mi = v[1] - v[0];
    for (int i = 1; i < n; ++i) {
        mi = min(mi, v[i+1] - v[i]);
    }

    int ans = mi;
    rep(i, n){
        ans = __gcd(ans, v[i+1] - v[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n,m;
    cin>>n>>m;
    lli i,sum=0,c;
    
    for(i=0;i<m;i++) cin>>c,sum+=c;
    
    if(sum>n) cout<<-1;
    else
    {
        cout<<n-sum;
    }
    return 0;
}

Measured memory_bytes: 3652
n1, n2, n3 = gets.split(' ').map(&:to_i)
n4 = n1
n1 = [n1 - n3, 0].max
n5 = [n3 - n4, 0].max
n2 = [n2 - n5, 0].max

printf("%i %i\n", n1, n2)

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e3 +10;

const int inf = 1e9;

int n, m;
string g[maxn];
int dp[maxn][maxn];

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

    cin>>n>>m;
    

    int a,b,x,y;
    cin>>a>>b>>x>>y;
    --a; --b;
    --x; --y;

    for (int i=0; i<n; i++) {
	cin>>g[i];
    }

    for (int i=0; i<n; i++) {
	for (int j=0; j<m; j++) {
	    dp[i][j]=inf;
	}
    }

    dp[a][b]=0;

    set<pair<int,pair<int,int>>> st;
    for (int i=0; i<n; i++) {
	for (int j=0; j<m; j++) {
	    st.insert({dp[i][j],{i,j}});
	}
    }


    while (st.size()) {
	auto cur = *st.begin();
	st.erase(st.begin());
	if (cur.first == inf) continue;
	int sx=cur.second.first;
	int sy=cur.second.second;
	for (int dx=-2; dx<=2; dx++) {
	    for (int dy=-2; dy<=2; dy++) {
		int tx=dx+sx;
		int ty=dy+sy;
		if (tx<0||ty<0||tx>=n||ty>=m) continue;
		if (g[tx][ty]=='#') continue;
		int walk = abs(sx-tx)+abs(sy-ty);
		int dist = -1;
		if (walk==1) {
		    dist = cur.first + 0;
		} else {
		    dist = cur.first + 1;
		}
		if (dist < dp[tx][ty]) {
		    st.erase({dp[tx][ty], {tx,ty}});
		    dp[tx][ty]=dist;
		    st.insert({dp[tx][ty], {tx,ty}});
		}
	    }
	}
    }

    int ans = dp[x][y]==inf ? -1: dp[x][y];
    cout<<ans<<endl;    
    return 0;
}


Measured memory_bytes: 71120
N = int(input())
A = list(map(int, input().split()))

A = [0] + A + [0]
D = [abs(A[i + 1] - A[i]) for i in range(len(A) - 1)]
total = sum(D)

for i in range(1, N + 1):
    res = total + abs(A[i + 1] - A[i - 1])
    res -= abs(A[i + 1] - A[i]) + abs(A[i] - A[i - 1])
    print(res)


Measured memory_bytes: 66284
MM = input().split()
N = int(MM[0])
K = int(MM[1])
LL = input().split()
list1 =[]
for i in LL:
  a = int(i)
  list1.append(a)
list1.sort(reverse = True)

total = 0
for i in range(K):
  total += list1[i]
print(total)
  

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

#define ll long long
#define fr(i,a,b) for (int i=a ; i<b ; i++)
#define fre(i,a,b) for (int i=a ; i<=b ; i++)
#define mem(a, b) memset(a, (b), sizeof(a))
#define mp make_pair
#define pb push_back
#define inf (int)1e9
#define pii 3.1415926535897932384626433832795
#define mod 1000000007
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pi> vii;
typedef map<int,int> mi;
typedef set<int> si;

int a[100005];
int dp[100005];


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n; cin>>n;
    fre(i,1,n)
    	cin>>a[i];
    mem(dp,-1);
    dp[1] = 0;
    dp[2] = abs(a[2] - a[1]);
    for(int i=3;i<=n;i++){
    	dp[i] = min(abs(a[i]-a[i-1]) + dp[i-1] , abs(a[i] - a[i-2]) + dp[i-2]);
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 4420
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll N;
    cin>>N;
    v A(N);
    rep(i,0,N)cin>>A[i];
    map<ll,ll> m;
    map<ll,bool> ok;
    rep(i,0,N){
        m[A[i]]++;
        ok[A[i]] = false;
    }
    v ans;
    rep(i,0,N){
        
        if(!ok[A[i]]){
            if(m[A[i]] >= 2){
                ans.push_back(A[i]);
            }
            if(m[A[i]] >= 4){
                ans.push_back(A[i]);
            }
            ok[A[i]] = true;
        }
    }
    sort(all(ans));
    if(ans.size() <=1)cout<<0;
    else {cout<<ans[ans.size()-1] * ans[ans.size()-2];
    return 0;
    }
}

Measured memory_bytes: 13568
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

pair<int, string> pairif[110000];

int main(){
    string str1, str2;
    cin >> str1 >> str2;

    cout << str2 << str1 << endl;
    return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n; cin>> n;
  int cnt4 = 0;
  int cnt2 = 0;
  int cnt1 = 0;
  for(int i=0;i<n;i++){
    int a; cin >> a;
    if(a%4==0) cnt4++;
    else if(a%2==0) cnt2++;
    else cnt1++;
  }
  if(cnt2 == 0){
    if(cnt1 <= cnt4 + 1) cout << "Yes" << endl;
    else cout << "No" << endl;
  }else{
    if(cnt1 <= cnt4) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

int main(void){
  int n, m;
  cin >> n >> m;
  vector<bool> Scheck(n), Gcheck(n);
  
  
  for(int i = 0;i < m;i++){
    int x, y; cin >> x >> y;
    if(x == 1) Scheck[y-1] = true;
    if(y == n) Gcheck[x-1] = true;
  }
  
  for(int i = 0;i < n;i++){
    if(Scheck[i] == true && Gcheck[i] == true){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  
  cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<string>
#include <ios>     
#include <iomanip> 
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

llong gcd(llong a, llong b) {
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}

llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}

//ここまで共通

int H, W;
char S[2010][2010];

int A[2010][2010];
int B[2010][2010];

int ans = 0;

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {

			A[i][j] = 0;
			int tmp = 0;
			if (S[i][j] == '#') {
				;
			}
			else {

				tmp++;
				

				if (S[i - 1][j] == '.') {
					A[i][j] = A[i - 1][j];
				}
				else {
					for (int k = i; S[k][j] == '.'; k++) {
						A[i][j]++;
					}


					for (int k = i; S[k][j] == '.' && k >= 0; k--) {
						A[i][j];
					}
				}

				if (S[i][j - 1] == '.') {
					B[i][j] = B[i][j - 1];
				}

				else {
					for (int k = j; S[i][k] == '.'; k++) {
						B[i][j]++;
					}


					for (int k = j; S[i][k] == '.' && k >= 0; k--) {
						B[i][j]++;
					}
				}

				tmp = A[i][j] + B[i][j] - 2;
			}

			ans = max(ans, tmp);

		}
	}

	cout << ans;
}

Measured memory_bytes: 35712
#include <iostream>
#include <cmath>
#include <cstdio>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main(){
    ll x;
    cin>>x;
    if(x==3 or x==5 or x==7){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;
const ll INF  = 1000000000000;
const ll m = 1000000007;
typedef pair<ll, ll> P;
map<ll, ll> mp; 

int prime_factorize(ll n) {

  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll ex = 0;
    while (n % i == 0) { ++ex; n /= i; }

    auto itr = mp.find(i);
    if (itr == mp.end()) mp[i] = ex;
    else mp[i] += ex;
      
  }

  if (n != 1) {
    auto itr = mp.find(n);
    if (itr == mp.end()) mp[n] = 1;
    else mp[n]++;
  }

  return 0;
}

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

    ll N;
    cin >> N;

    while(N > 0){
      prime_factorize(N);
      N--;
    }

    ll ans = 1;
    for (auto itr = mp.begin(); itr != mp.end(); itr++)  {
      ll ex = itr->second;
      ans *= (ex + 1);
      ans %= m;
    }

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


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W,N,ans;
  cin>>H>>W>>N;
  if(H>=W){
    if(N%H==0){
      ans=N/H;
    }
    else{ans=N/H+1;}
  }else {
      if(N%W==0){ans=N/W;}
      else{ans=N/W+1;}
    }
    cout<<ans<<endl;  
}

Measured memory_bytes: 256
from math import floor
a,b=map(int,input().split())

root=floor(a*100//8)

while True:
    if (a==int(floor(root*0.08)))&(b==int(floor(root*0.1))):
        ans=int(root)
        break
    else:
        if (int(floor(root*0.08))>a)|(int(floor(root*0.1))>b):
            ans=-1
            break
        root+=1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
  int A, B;
  string S;
  cin >> A >> B >> S;
  string ans = "Yes";
  for (int i = 0; i < A; i++)
  {
    if (S[i] == '-')
      ans = "No";
  }
  if (S[A] != '-')
    ans = "No";
  for (int i = A + 1; i <= A + B; i++)
  {
    if (S[i] == '-')
      ans = "No";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int i,j;

	for(i=1; i<=9; i++)
	{
		for(j=1; j<=9; j++)
		{
			cout << i << "x" << j << "=" << i*j << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0