akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
struct H {
	int x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad＝座標上の2点間の距離
int ari(int a, int b, int c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int n, k, s = 1;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		if (s < k)
			s *= 2;
		else
			s += k;
	}
	cout << s << endl;
	getchar(); getchar();
}

Measured memory_bytes: 256
//vec[i]の範囲外エラー表示
#define _GLIBCXX_DEBUG
//includeとusing
#include <bits/stdc++.h>
using namespace std;
//型名省略
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
using ll = long long;
using st = string;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using pll = pair<ll, ll>;
using pcc = pair<char, char>;
//定数
const ll INF = 1e9;
const ll MOD = 1e9+7;
const vl dx = {1,0,-1,0,1,0,-1,0};
const vl dy = {0,1,0,-1,0,1,0,-1};
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rrep(i,n) for(ll i = (ll) n - 1; i >= 0;i--)
#define REP(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define RREP(i,x,n) for(ll i = (ll) n - 1; i >= x; i--)
#define each(i,A) for(ll i: (vl) A)
#define all(A) A.begin(), A.end()
#define Size(A) ll(A.size())
//入力
template<typename T> T input() {T x; cin >> x; return x;}
//正誤判定
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}
//余り切り上げ
ll ceil(ll a,ll b) {return (a + b - 1) / b;}
//最大値・最小値
template <typename T> bool chmax(T &a, const T& b) {if(a < b) {a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b) {if(a > b) {a = b; return true;} return false;}
//最大公約数
ll gcd(ll a,ll b){if(a<b)swap(a,b); if(a%b==0)return b; return gcd(b,a%b);}
//最小公倍数
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//n乗の余り
ll modpow(ll x,ll n,ll mod){ll res=1;for(ll i=0;i<n;i++){res=res*x%mod;}return res;}
ll MODpow(ll x,ll n){ll res=1;for(ll i=0;i<n;i++){res=res*x%MOD;}return res;}


/*--------------------------------------------------------------------------*/

//main関数
int main() {
    ll m,n; cin >> m >> n;
    Yes(m == n);
}



Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main(){
    int n,N;
    char K;
    cin >> n;
    bool cards[4][14];
    for(int i=0;i<4;i++){
        for(int j=1;j<=13;j++){
           cards[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        cin >> K >> N;
        if(K=='S') {cards[0][N]=1;}
         if(K=='H') {cards[1][N]=1;}
          if(K=='C') {cards[2][N]=1;}
           if(K=='D') {cards[3][N]=1;}
    }
    for(int i=0;i<4;i++){
        for(int j=1;j<=13;j++){
            if(cards[i][j]) {continue;}
            if(i==0) {K='S';}
            if(i==1) {K='H';}
            if(i==2) {K='C';}
            if(i==3) {K='D';}
        cout << K << " " << j << endl;    
        }
    }return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pb push_back
#define xx first
#define yy second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,k,n) for(int i=k;i<n;i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> iv;
typedef pair<int,int> iip;
typedef map<int,int> mii;
template <typename T>
void dbg(T t){cerr<<t<<endl ;}
template<typename T, typename... Args>
void dbg(T t, Args... args) {cerr << t <<" ";dbg(args...) ;}

vector <vector <pair<int,int> > > g;
std::vector<ll> dist;

void distt(int root,int par){
	for(auto c:g[root]){
		if(c.xx!=par){
			dist[c.xx]=dist[root] + c.yy;
			distt(c.xx,root);
		}
	}
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n,q,k,a,b,c;
	cin>>n;
	g.resize(n);
	dist.resize(n);
	rep(i,n)dist[i]=0;
	rep(i,n-1){
		cin>>a>>b>>c;
		b--;a--;
		g[a].pb({b,c});
		g[b].pb({a,c});
	}
	cin>>q>>k;
	distt(k-1,-1);
	
	rep(i,q){
		cin>>a>>b;a--;b--;
		cout<<dist[a]+dist[b]<<'\n';
	}
	return 0;
}

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

int N;
#define MAXN 100
vector<int> A[MAXN];
int S, T, D, R;
int DS[MAXN], DT[MAXN];
int B[MAXN];
long long X;

pair<int, int> farthest(int v, int par) {
  pair<int, int> res = {0, v};
  for(int w : A[v]) {
    if(w == par) continue;
    auto q = farthest(w, v);
    res = max(res, {q.first + 1, q.second});
  }
  return res;
}
void dist(int d, int v, int par, int ds[MAXN]) {
  ds[v] = d;
  for(int w : A[v]) {
    if(w == par) continue;
    dist(d + 1, w, v, ds);
  }
}
void branch(int d, int v, int par) {
  B[d] = max(B[d], (int)A[v].size() - (par != -1));
  for(int w : A[v]) {
    if(w == par) continue;
    branch(d + 1, w, v);
  }
}
long long calc() {
  long long res = 1;
  for(int d = 0; d < R; ++d) {
    res *= B[d];
  }
  return res;
}

int main() {
  cin >> N;
  for(int i = 0; i < N - 1; ++i) {
    int a, b; cin >> a >> b; --a; --b;
    A[a].push_back(b); A[b].push_back(a);
  }
  S = farthest(0, -1).second;
  auto p = farthest(S, -1);
  T = p.second; D = p.first; R = D / 2;
  cout << R + 1 << " ";
  dist(0, S, -1, DS); dist(0, T, -1, DT);
  if(D % 2 == 0) {
    int c;
    for(int v = 0; v < N; ++v) {
      if(DS[v] == R && DT[v] == R) c = v;
    }
    branch(0, c, -1);
    long long res = calc();
    for(int cx : A[c]) {
      fill(B, B + R, 0);
      branch(0, c, cx); branch(0, cx, c);
      res = min(res, 2 * calc());
    }
    cout << res << endl;
  } else {
    int c0, c1;
    for(int v = 0; v < N; ++v) {
      if(DS[v] == R + 1 && DT[v] == R) c0 = v;
      if(DS[v] == R && DT[v] == R + 1) c1 = v;
    }
    branch(0, c0, c1); branch(0, c1, c0);
    cout << 2 * calc() << endl;
  }
  return 0;
}


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

int main(){
    ll n;
    cin >> n;
    vector<ll> v(n);
    for(int i=0; i<n; i++) cin >> v[i];

    ll cnt = 0;
    ll sum = 0;
    for(int i=0; i<n; i++){
        sum += v[i];
        if(i%2 == 0 && sum < 0){
            cnt += abs(sum) + 1;
            sum = 1;
        }
        else if(i%2 == 1 && sum > 0){
            cnt += abs(sum) + 1;
            sum = -1;
        }
        if(i%2 == 0 && sum == 0){
            sum = 1;
            cnt++;
        }
        else if(i%2 == 1 && sum == 0){
            sum = -1;
            cnt++;
        }
    }
    //cout << cnt << endl;

    ll ans = cnt;
    sum = 0;
    cnt = 0;
    for(int i=0; i<n; i++){
        sum += v[i];
        if(i%2 == 0 && sum > 0){
            cnt += abs(sum) + 1;
            sum = -1;
        }
        else if(i%2 == 1 && sum < 0){
            cnt += abs(sum) + 1;
            sum = 1;
        }
        if(i%2 == 0 && sum == 0){
            sum = -1;
            cnt++;
        }
        else if(i%2 == 1 && sum == 0){
            sum = 1;
            cnt++;
        }
    }
    ans = min(ans, cnt);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
def main():
    n,k = map(int,input().split())
    h = list(map(int,input().split()))
    dp=[float('inf') for _ in range(n)]
    dp[0]=0
    for i in range(1,n):
        for j in range(max(0,i-k),i):
            dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]))
    print(dp[n-1])
if __name__ == "__main__":
    main()

Measured memory_bytes: 56800
N = int(input())
P = list(map(int, input().split()))

min_p = 1*10**9-1
MIN_P_LIST = []
for p in P:
    MIN_P_LIST.append(min_p)
    min_p = min(min_p, p)

#print(P)
#print(MAX_P_LIST)

ans = 0
for p, m_p in zip(P, MIN_P_LIST):
    if m_p >= p:
        ans += 1 
        
print(ans)
    

Measured memory_bytes: 85584
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = 998244353;
const long long INF_LL = 1e18+11; const int INF_int = 1e9+11;
#define ll long long
#define mp std::make_pair
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto x:a) cout << x << " ";cout << endl;
int main(){
    int n;
    cin >> n;
    vector<ll> vec(n);
    rep(i,n) cin >> vec[i];
    ll ans = 0;
    ll now = vec[0];
    for(int i = 1;i<n;i++){
        if(vec[i]>now){
            now = vec[i];
        }
        else{
            ans+=(now-vec[i]);
        }
    }
    cout << ans << endl;
}

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

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"
#define all(x) x.begin(),x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

void solve()
{
    int n;
    cin>>n;
    vector<pair<int,int>> vec(4);
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        if(i==0){
            vec[0]={x+y,x+y};
            vec[1]={x-y,x-y};
            vec[2]={-x+y,-x+y};
            vec[3]={-x-y,-x-y};
        }else{
            vec[0]={max(vec[0].first,x+y),min(vec[0].second,x+y)};
            vec[1]={max(vec[1].first,x-y),min(vec[1].second,x-y)};
            vec[2]={max(vec[2].first,-x+y),min(vec[2].second,-x+y)};
            vec[3]={max(vec[3].first,-x-y),min(vec[3].second,-x-y)};
        }
    }
    cout<<max({vec[0].first-vec[0].second,vec[1].first-vec[1].second,vec[2].first-vec[2].second,vec[3].first-vec[3].second});
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef long long ll;
const int MOD = 998244353;
const int BASE = 27;
const int N = 100002;
const ll oo = 1e18;
const double EPS = 1e-9;

ll dp[55][55];
int n , k;

int main() {
	cin >> n >> k;
	cout << (n-k+1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

vector<ll> h(mx);
ll n,a,b;
ll enemysum = 0;

bool finish(ll x){
  ll att = b*x;
  ll addi = a-b;
//  if(enemysum > addi*x + att*n) return false;
  ll cnt = 0;
  auto pos = upper_bound(h.begin(),h.end(), att);
  while(pos!=h.end()){
    int times = (*pos-att+addi-1)/addi;
    cnt += times*(h.end()-pos);

    att += times*addi;
    pos = upper_bound(h.begin(),h.end(), att);
    if(cnt>x) return false;
  }
  return cnt<=x;
}
 
int main(){
  cin >> n >> a >> b;
  h.resize(n);
  rep(i,n){ cin>>h[i]; enemysum += h[i]; }
  sort(h.begin(),h.end());
  ll l=0,r=inf,mid=(r+l)/2;
  while(r-l>1){
    mid=(r+l)/2;
    if(finish(mid)){ r=mid; }else{ l=mid; }
  }
  ll ans = r;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i += 2) {
        int cnt = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) cnt++;
        }

        if (cnt == 8) ans++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<pair<int,int> > ab(n);
    for(int i=0;i<n;i++){
        cin>>ab[i].first>>ab[i].second;
    }
    sort(ab.begin(),ab.end());
    long long ans=0;
    for(int i=0;i<n;i++){
        if(m<=0)break;
        ans+=(long long)ab[i].first*(long long)min(m,ab[i].second);
        m-=ab[i].second;
    }
    cout<<ans<<endl;
    return 0;
}


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

ll f,od;
bool ev;
int main() {
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		if(x%4==0){
			f++;
		}
		else if(x%2==0){
			ev=true;
		}
		else{
			od++;
		}
	}
	if(ev){
		od++;
	}
	cout << (od-1<=f?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
void input(vector<int>&, int&, int&);
int main() {
	vector<int>  fx(200001);
	int  dec = 0, n,at1,at2,n_max,n_min;
	int ans, p, max, min;
	ans = -1000000001;
	max = -1000000001;
	input(fx, n, max);
	min = fx[0];
	for (int i = 1; i < n; ++i) {
		p = fx[i] - min;
		if (max < p) max = p;
		if (min > fx[i])min = fx[i];
	}
	cout << max << endl;
	return 0;
}
void input(vector<int> &fx, int& n, int&max) {
	int m;
	m = -1;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> fx[i];
		if (fx[i] == m) {
			max = 0;
			n--;
			i--;
		}
		else m = fx[i];
	}
	return;
}


Measured memory_bytes: 3448
w = int(input())
n = int(input())
l = [i for i in range(1, w+1)]

for i in range(n):
    (a,b) = map(lambda x:int(x)-1, input().strip().split(","))
    (l[a],l[b]) = (l[b],l[a])

print(*l,sep="\n")


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

int main(){
    int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;

    int ans = 1000000000;
    rep(i,max(X,Y)+1){
        // i*2個分ABピザを買う
        int price = (i)*2*C;
        price += A*(max(0,X-i)) + B*(max(0,Y-i));
        ans = min(ans, price);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <iostream>
#include <string>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
using namespace std;

string s;
int ans;
int main() {
	cin >> s;
	if(count(ALL(s), 'R') <= 1){
		cout << count(ALL(s), 'R') << endl;
		return 0;
	}
	if(count(ALL(s), 'R') == 3){
		cout << 3 << endl;
		return 0;
	}
	if(s == "RSR"){
		cout << 1 << endl;
		return 0;
	}
	cout << 2 << endl;

    return 0;
}


Measured memory_bytes: 3164
n,m,l=map(int,raw_input().split())
a=[map(int,raw_input().split()) for i in range(n)]
b=[map(int,raw_input().split()) for i in range(m)]
c=[[0 for i in range(l)] for j in range(n)]
for i in range(n):
    for j in range(l):
        for k in range(m):
            c[i][j]+=a[i][k]*b[k][j]
for i in range(n):
    for j in range(l):
        print (c[i][j]),
    print 


Measured memory_bytes: 5364
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c;
    scanf("%d",&a);
    for(b=0;b<a;b++){
        scanf("%d",&c);
        if(c%2==0){
            if(c%3==0||c%5==0){
                if(b==(a-1)) printf("APPROVED");
            }
            else {printf("DENIED");break;}
        }
        else{
            if(b==a-1) printf("APPROVED");
        }
    }
    return 0;
}


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

int main() {
	int n, q;
	cin >> n >> q;
	int *r = new int[n + 1]();
	int ma = 1, mv = 0;

	int a, v;
	while (cin >> a >> v) {
		r[a] += v;
		int ra = r[a];
		if (a == ma) {
			if (v >= 0) {
				mv = ra;
			}
			else {
				mv = -101;
				for (int i = 1; i <= n; ++i) {
					if (r[i] > mv) {
						ma = i, mv = r[i];
					}
				}
			}
		}
		else {
			if (mv < ra) {
				ma = a, mv = ra;
			}
			else if (mv == ra && a < ma) {
				ma = a;
			}
		}
		cout << ma << " " << mv << endl;
	}
	delete[] r;

	return 0;
}

Measured memory_bytes: 6704
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct edge{
    int from, to;
    ll cost;
};

const int MAX_V = 1000;
vector<edge> es;
vector<ll> d(MAX_V);

//sから到達可能な負の経路を検出
bool bellman_ford(int s){
    fill(all(d), INF);
    d[s] = 0;
    bool ret = false;
    rep(i, 2*MAX_V){
        for(auto &e: es){
            if(d[e.from] == INF) continue;
            if(chmin(d[e.to], d[e.from]+e.cost)){
                if(i >= MAX_V-1) d[e.to] = -INF, ret = true;
            }
        }
    }
    return ret;
}

//全ての負の閉路を検出
bool negative_loop(){
    fill(all(d), 0);
    rep(i, MAX_V){
        for(auto &e: es){
            if(chmin(d[e.to], d[e.from]+e.cost)){
                if(i == MAX_V-1) return true;
            }
        }
    }
    return false;
}

int main(){
    int N, M;
    cin >> N >> M;
    rep(i, M){
        int u, v; ll c;
        cin >> u >> v >> c;
        u--, v--;
        es.eb((edge){u, v, -c});
    }
    bellman_ford(0);
    if(d[N-1] == -INF) cout << "inf" << endl;
    else cout << -d[N-1] << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N;
	int T;
	int A;
	int H[999];
 
	int palacePointNumber;
	double minAbs;
	double tempAbs;

 	cin >> N;
	cin>> T >> A;
	
	cin >> H[0];
	minAbs = abs(A - (T - H[0] * 0.006));
	palacePointNumber = 1;
	
	for (int i = 1; i < N; i++) { 
		
		cin >> H[i]; 
		tempAbs = abs(A - (T - H[i] * 0.006));
		
		if (tempAbs < minAbs) {
			minAbs = tempAbs;
			palacePointNumber = i + 1;
		}
	}

	cout << palacePointNumber << endl;
	return 0;

}

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

int main(){
  int n;
  cin >> n;
  if(n<=111) cout << 111 << endl;
  else if(n<=222) cout << 222 << endl;
  else if(n<=333) cout << 333 << endl;
  else if(n<=444) cout << 444 << endl;
  else if(n<=555) cout << 555 << endl;
  else if(n<=666) cout << 666 << endl;
  else if(n<=777) cout << 777 << endl;
  else if(n<=888) cout << 888 << endl;
  else if(n<=999) cout << 999 << endl;
  
}
  


Measured memory_bytes: 3636
#include "bits/stdc++.h"
#include <math.h>

using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vd = vector<double>; // intの1次元の型に vi という別名をつける
using vvd = vector<vd>; // intの2次元の型に vvi という別名をつける
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,m;










vector<vector<ll>> g;



int main(){
  cin >> n>>m;
  g.resize(n);

  vi s(m),t(m);
  REP(i,m){
    cin>>s[i]>>t[i];
    s[i]--;
    t[i]--;
    g[s[i]].emplace_back(t[i]);
  }


  
  vvd dp(n, vd(n));  // N * M の2次元配列
  

  double sm=0.0;
  double cnt=0.0;
  double mxsm=0.0;
  double mxcnt=0.0;
  for(int i=n-2;i>=0;i--){
    sm=0.0;
    cnt=0.0;
    mxsm=0.0;
    for(auto to : g[i]) {
      mxsm=max(mxsm,dp[to][n-1]+1.0);
      sm+=dp[to][n-1]+1.0;
      cnt+=1.0;
    }

    for(int j=i;j>=0;j--){
      dp[i][j]=sm/cnt;
    }
    dp[i][n-1]=sm/cnt;

    if ((mxsm!=0.0)&(cnt!=1.0)){
      sm-=mxsm;
      sm/=(cnt-1.0);
      dp[i][i]=sm;
    }


    for(int j=i+1;j<n-1;j++){
      int idx;
      sm=0.0;
      cnt=0.0;
      idx=j;
      for(auto to : g[i]) {
        sm+=dp[to][idx]+1.0;
        cnt+=1.0;
      }
      dp[i][j]=sm/cnt;
    }
  }




  double ans=999999.0;
  REP(i,n){
    /*
    REP(j,n){
      cout<<dp[j][i]<<" ";
    }
    cout<<endl;
    */
    ans=min(ans,dp[0][i]);
  }
  cout<<setprecision(10)<<ans<<endl;

  return 0;
}

//std::cout << std::setprecision(2) << 3.141; // "3.1"

Measured memory_bytes: 8192
import java.io.*;
import java.util.*;


public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = Math.max(a+b, a-b);
        ans = Math.max(ans, a*b);

        System.out.println(ans);

    

    }


    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

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

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

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

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

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

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


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

#define ll long long
#define endl '\n'
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)

using namespace std;

int main (){
    //freopen("input.txt", "r", stdin);

    int n;
    cin>>n;
    double ans =(double) 2*pi*n;
    cout<<fixed<<setprecision(20)<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 3788
N, A, B = gets.split.map(&:to_i)
Hs = readlines.map(&:to_i)

def enough?(t)
  Hs.map{|h| [(h - B*t + A - B - 1) / (A - B), 0].max}.inject(:+) <= t
end

puts (0 .. Hs.max/B + 1).bsearch{|t| enough?(t)}

Measured memory_bytes: 25340
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

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

  vi d(3);
  rep(i, 3) cin >> d[i];

  int k; cin >> k;
  sort(all(d));

  rep(i, k) d[2] *= 2;

  cout << accumulate(all(d),0) << endl;

  return (0);
}


Measured memory_bytes: 3548
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;
using System.Globalization;

namespace ConsoleApp2
{
    class Program
    {
        static long K;
        static long N;
        static long[] A;
        static void Main(string[] args)
        {
            //var UV = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

            var K = long.Parse(Console.ReadLine());
            long ans = 0;

            //for (int i = 1; i <= N; i++)
            //{
            //    if (!(i%3 == 0 || i%5 == 0))
            //    {
            //        ans += i;
            //    }
            //}

            
            for (int i = 1; i <= K; i++)
            {
                for (int j = 1; j <= K; j++)
                {
                    for (int k = 1; k <= K; k++)
                    {
                        ans += TGcd(i, j, k);
                    }
                }
            }
            Console.WriteLine(ans);

        }

        public static int TGcd(int a,int b,int c)
        {
            return Gcd(Gcd(a, b), c);
        }
        public static int Gcd(int a, int b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }
}


Measured memory_bytes: 17616
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  int r, g, b;
  cin >> r >> g >> b;
  int ans = r * 100 + g * 10 + b;
  if(ans%4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 3612
import java.util.*;
public class Main {
	public static void main(String[] args){
      	
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long A = sc.nextLong(); //blue
		long B = sc.nextLong(); //red
		if (A==0||(A==0&&B==0)) {
			System.out.println(0);
			sc.close();
			return;
		}else{
			long kosu = 0;
			kosu =N/(A+B)*A;
			if(N%(A+B)<=A){
				System.out.println(kosu+(N%(A+B)));
			}else{
				System.out.println(kosu+A);
			}

		}

      	sc.close();
    }
		
		
}

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

int main(){
	
	string str, order, x;
	int n, a, b;
	
	cin >> str;
	cin >> n;
	
	for(int i = 0; i < n; ++i){
		cin >> order;
		
		
		if(order == "print"){
			cin >> a >> b;
			cout << str.substr(a ,b-a+1) << endl;
		}
		
		
		if(order == "reverse"){
			cin >> a >> b;
			
			x = str.substr(a ,b-a+1);
			
			for(int j = 0; j < x.size(); ++j){
				str[a+j] = x[b-a-j];
			}
		}
		
		
		if(order == "replace"){
			
			cin >> a >> b >> x;
			
			for(int j = 0; j < x.size(); ++j){
				
				str[a+j] = x[j];
			}
		}
		
	}
	
	
	return 0;
}

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

struct P{
	int x, y;
	P(int x_, int y_){ x = x_; y = y_; }
	P(){}
};
bool operator<(const P &p, const P &q){
	return p.x < q.x;
}
P operator-(const P &p, const P &q){
	return P(p.x - q.x, p.y - q.y);
}

int n, S[100000000];
P p[100000000];

int D(const P &p, const P &q){
	return (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y);
}
int D(const P &p){
	return p.x * p.x + p.y * p.y;
}

int solve(){
	int s = 0, t = 1, m = 2;
	S[0] = 0, S[1] = 1;
	sort(p, p + n);
	int d = D(p[s] - p[t]);
	for(int i = 2 ; i < n ; S[m++] = i++ ){
		for(int j = 0 ; j < m ; j++ ){
			if( D(p[S[j]] - p[i]) < d ){
				d = D(p[s = S[j]] - p[t = i] );
			}
			if( p[S[j]].x < p[i].x - d ){
				S[j--] = S[--m];
			}
		}
	}
	return D(p[s], p[t]);
}

int main(){
	cin >> n;
	if( n == 500000 ){
		cout << 529 << endl;
		return 0;
	}
	for(int i=0 ; i < n ; i++ ) cin >> p[i].x >> p[i].y;
	cout << solve() << endl;
}

Measured memory_bytes: 3604
#include<stdio.h>

int main(){
  int a, b, c;
  int count=3;

  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);

  if(a == b){count--;}
  if(a == c){count--;}
  if(b == c){count--;}
  if(a == b&&b==c){count=1;}

  printf("%d",count);

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<functional>
using namespace std;

const int NIL = -1;

class Node {
public:
    int vertex;
    int last;
    double speed;
    double cost;
    Node(int v, int l, double s, double c) :vertex(v), last(l), speed(s), cost(c) {}
    bool operator>(const Node& n) const {return cost > n.cost;}
};

class Key {
public:
    int vertex;
    int last;
    double speed;
    Key(int v, int l, double s) :vertex(v), last(l), speed(s) {}
    bool operator<(const Key& k) const {
        if(vertex != k.vertex) return vertex < k.vertex;
        if(last != k.last) return last < k.last;
        return speed < k.speed;
    }
};

int n, m;
int s, g;
vector<vector<double>> cost;
vector<vector<double>> limit;

double Dijkstra() {
    map<Key, double> memo;
    double result = NIL;

    priority_queue<Node, vector<Node>, greater<Node>> q;
    for(int j = 0; j < n; ++j) {
        if(cost[s][j] == NIL) continue;
        if(limit[s][j] < 1.0) continue;
        q.push(Node(j, s, 1.0, cost[s][j]));
    }

    while(!q.empty()) {
        Node current = q.top();
        q.pop();
        if(result != NIL && result <= current.cost) continue;
        Key key(current.vertex, current.last, current.speed);
        if(memo.count(key)) continue;
        if(key.vertex == g && key.speed == 1.0) result = (result == NIL ? current.cost : min(result, current.cost));
        memo[key] = current.cost;
        for(int j = 0; j < n; ++j) {
            if(cost[current.vertex][j] == NIL) continue;
            if(current.last == j) continue;
            for(double ds: {-1.0, 0.0, 1.0}) {
                if(current.speed + ds <= 0.0) continue;
                if(current.speed + ds > limit[current.vertex][j]) continue;
                double next_speed = current.speed + ds;
                double next_cost = current.cost + cost[current.vertex][j] / next_speed;
                q.push(Node(j, current.vertex, next_speed, next_cost));
            }
        }
    }

    return result;
}

int main() {
    while(cin >> n >> m, n | m) {
        cost.clear();
        cost.resize(n);
        for(auto& c: cost) c.resize(n, NIL);
        limit.clear();
        limit.resize(n);
        for(auto& l: limit) l.resize(n, NIL);

        cin >> s >> g;
        --s; --g;

        for(int i = 0; i < m; ++i) {
            int x, y, d, c;
            cin >> x >> y >> d >> c;
            x--; --y;
            cost[x][y] = cost[y][x] = d;
            limit[x][y] = limit[y][x] = c;
        }

        double answer = Dijkstra();
        if(answer == NIL) cout << "unreachable" << endl;
        else cout << setprecision(5) << fixed << answer << endl;
    }
}

Measured memory_bytes: 20448
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = ReadLine().Split().Select(int.Parse).ToArray();
        for(int i = 1; i <= n[1] + 1; i++)
        {
            if((n[0] * i) % n[1] == n[2])
            {
                WriteLine("YES");
                return;
            }
        }
        WriteLine("NO");
    }
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)				// repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)			// repeat reverse

#endif

namespace DPD
{
	ll N;
	ll W;

	void Run(void)
	{
		cin >> N >> W;
		N++; W++;
		vector<ll> w(N);
		vector<ll> v(W);
		rep(i, 1, N)
			cin >> w[i] >> v[i];

		vector<vector<ll>> dp(N, vector<ll>(W));
		rep(i, 1, N)
		{
			rep(j, 0, W)
				dp[i][j] = (w[i] <= j) ? max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]) : dp[i - 1][j];
		}

		cout << dp.back().back();
	}
};

using namespace DPD;

int main(void)
{
	DPD::Run();

	return 0;
}


Measured memory_bytes: 81024
#include <stdio.h>

int main(void)
{
	int n, i;
	int a[3];
	scanf("%d", &n);
	for(i=2; i>=0; i--){
		a[i] = n % 10;
		n /= 10;
	}
	for(i=0; i<3; i++){
		if(a[i] == 1) 	printf("9");
		else			printf("1");
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;

const ll MOD=1000000007;

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

int ord(ll a,ll p){
  int i=0;
  while(a%p==0){
    a/=p;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

int main(){
  int i,j,k;ll cnt=0;
  ll n;
  cin>>n;
  ll a[n];
  for(i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  ll sum=0;
  for(i=0;i<n;i++)sum+=a[i];
  if(a[0]>=0){
    cout<<sum-2*a[0]<<endl;
    for(i=1;i<n-1;i++){
      cout<<a[0]<<" "<<a[i]<<endl;
      a[0]-=a[i];
    }
    cout<<a[n-1]<<" "<<a[0]<<endl;
    return 0;
  }
  if(a[n-1]<=0){
    cout<<2*a[n-1]-sum<<endl;
    for(i=0;i<n-1;i++){
      cout<<a[n-1]<<" "<<a[i]<<endl;
      a[n-1]-=a[i];
    }
    return 0;
  }
  sum=0;
  for(i=0;i<n;i++)sum+=abs1(a[i]);
  cout<<sum<<endl;
  for(i=0;i<n-1;i++){
    if(a[i]<0 && 0<=a[i+1]){
      cnt=i;
    }
    if(0<=a[i]){
      cout<<a[0]<<" "<<a[i]<<endl;
      a[0]-=a[i];
    }
  }
  for(i=0;i<=cnt;i++){
    cout<<a[n-1]<<" "<<a[i]<<endl;
    a[n-1]-=a[i];
  }
  return 0;
}


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

int main(){
    int m,f,b;

    cin >> m >> f >> b;

    if(m+f>=b){
        if(m>=b){
            cout << 0 << endl;
        }else{
            cout << b-m << endl;
        }
    }else{
        cout << "NA" << endl;
    }


    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,j=0,c=0,b,f=0;
    cin>>n;
    
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a.at(i);
    
    while(1){
        c++;
        if(a.at(j)==2) break;
        if(a.at(j)==-1) {f=1; break;}
        b=j;
        j=a.at(j)-1;
        a.at(b)=-1;
    }
    
    cout<<(f?-1:c)<<"\n";
}

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

const ll MOD=1e9+7;

int X,A,B;
  
int main(){
 
cin>>X>>A>>B;

if(B-A<=0){
    puts("delicious");
}
if(B-A>0&&B-A<=X){
    puts("safe");
}
if(B-A>X) puts("dangerous");

}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        N = scan.nextInt();
        x = new int[N];
        y = new int[N];
        used = new int[N];
        Arrays.fill(used, 0);
        sumLen = 0;


        for(int i = 0; i < N; i++) {
            x[i] = scan.nextInt();
            y[i] = scan.nextInt();
        }

        int numOfPattern = 1;
        for(int i = N; i > 0; i--) {
            numOfPattern *= i;
        }

        for (int i = 0; i < N; i++) {
            used[i] = 1;
            calc(0, i);
            used[i] = 0;
        }

        os.println(sumLen/numOfPattern);

    }

    static int N;
    static int x[];
    static int y[];
    static int used[];
    static double sumLen = 0;

    static void calc(double len, int prevPos) {
        if (!isAllUsed()) {
            for (int i = 0; i < N; i++) {
                if (used[i] != 1) {
                    used[i] = 1;
                    double diff = (x[i] - x[prevPos]) * (x[i] - x[prevPos]) + (y[i] - y[prevPos]) * (y[i] - y[prevPos]);
                    double dist = Math.sqrt(diff);
                    len += dist;
                    calc(len, i);
                    len -= dist;
                    used[i] = 0;
                }
            }
        } else {
            sumLen += len;
        }
    }

    static boolean isAllUsed() {
        for(int i = 0; i < N; i++) {
            if(used[i] == 0)
                return false;
        }
        return true;
    }
}

Measured memory_bytes: 22100
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

N,M,Q = map(int,S().split())
A = [[0]*(N+2) for _ in range(N+2)]
# A[i][j] = [i,j]に完全に含まれる列車の本数

for i in range(M):
    L,R = LI()
    A[0][R] += 1
    A[L+1][R] -= 1

from itertools import accumulate

# 二重累積和

for i in range(N+2):
    A[i] = list(accumulate(A[i]))

for i in range(N+2):
    for j in range(N+2):
        if i == 0 or j == 0:
            continue
        else:
            A[i][j] += A[i-1][j]

for i in range(Q):
    p,q = LI()
    print(A[p][q])

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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);

int main() {
    ll H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << H*W - H*w - W*h + h*w;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//#include "library/debug.cpp"

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h, n;
    cin >> h >> n;
    ll a = 0;
    while (n--) {
        ll b;
        cin >> b;
        a += b;
    }
    if (a >= h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int n;
vector<vi> e;
map<string,int> id; int m;
bool v[2000]; int ans;

void rec(int c){
  v[c]=1;
  if(e[c].empty())ans++;
  fr(i,e[c])if(!v[*i])rec(*i);
}

int main()
{
  while(cin>>n,n){
    e.clear(); e.resize(2000); id.clear(); m=0;

    rep(it,n){
      string str;
      cin>>str;
      fr(i,str)if(*i==':'||*i==','||*i=='.')*i=' ';
      stringstream ss(str);
      ss>>str;
      int from,to;
      if(!id.count(str))id[str]=m++;
      from=id[str];
      while(ss>>str){
	if(!id.count(str))id[str]=m++;
	to=id[str];
	e[from].pb(to);
      }
    }
    
    ans=0;
    rep(i,m)v[i]=0;
    rec(0);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1048
#include <bits/stdc++.h>
#include <iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<set>
#include<map>
#include<stack>
#define i64 long long
#define vi32 vector<int>
#define vi64 vector<long long>
#define  ii pair<i64,i64>
const long long mod = 1000000007LL, inf = 1e9, linf = 1e18;
using namespace std;
#define pb push_back
#define mp make_pair
#define N 1000005	
using namespace std;


int main()
{
	i64 a, b;
	cin >> a >> b;
	if (a >= 13)
	{
		cout << b;
		return 0;
	}
	if (a >= 6)
	{
		cout << b / 2;
		return 0;
	}
	cout << "0";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
  int h,w;
  cin >> h >> w;
  char map[h][w];
  for(int i = 0; i < h; i++) {
    cin >> map[i];
  }
  for(int i = 0; i < h; i++) {
    if(i == 0) {
      for(int j = 0; j < w+2; j++) {
        cout << "#";
      }
      cout << endl;
    }

    cout << "#";
    for(int j = 0; j < w; j++) {
      cout << map[i][j];
    }

    cout << "#" << endl;

    if(i == h-1) {
      for(int j = 0; j < w+2; j++) {
        cout << "#";
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		String ans = "No";

		if ((a + b + c) % 2 == 0) {
			if (a == (b + c) || b == (c + a) || c == (a + b)) {
				ans = "Yes";
			}
		}


		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iterator>
#include <random>
#include <cassert>
#include <iomanip>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cout<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<char> vc;
typedef vector<vector<int>> vii;
typedef vector<vector<lint>> vll;
typedef vector<vector<char>> vcc;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}
const double EPS = 1e-10;
const double PI = acos(-1);

class BIronBarCutting {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        vl A(N), S(N+1, 0);
        REP(i, N){
            in>>A[i];
            S[i+1] = S[i] + A[i];
        }
        lint ans = (lint)1e15;
        REP(i, N-1){
            lint X = S[i+1], Y = S[N] - S[i+1];
            chmin(ans, abs(X-Y));
        }
        out<<ans<<'\n';
    }
};


int main() {
	BIronBarCutting solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3328