akhauriyash/Code-Regression huggingface dataset:
from itertools import permutations, combinations
from math import sqrt, factorial

n = int(input())
d = []
for _ in range(n):
    x, y = map(int, input().split())
    d.append((x, y))

l = [[0 for _ in range(n)] for _ in range(n)]
# print(d)
# print(l)

for i, j in combinations(range(n), 2):
    # print("comb:", i, j)
    dist = (d[i][0] - d[j][0]) ** 2 + (d[i][1] - d[j][1]) ** 2
    dist = sqrt(dist)
    # print(dist)
    # print(i, j)
    l[i][j] = dist
    l[j][i] = dist


# print(l)

s = 0
for p in permutations(range(n)):
    # print(p)
    for k in range(len(p) - 1):
        s += l[p[k]][p[k + 1]]

print(s / factorial(n))


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

using namespace std;

int main() {
    long long x, y;
    scanf("%lld%lld", &x, &y);

    long long gcd = __gcd(x, y);
    int res = 0;

    for (int i = 2; i <= sqrt(gcd); i++) {
        if (gcd % i == 0) res++;
        while (gcd % i == 0) {
            gcd /= i;
        }
    }

    if (gcd > 1) res++;

    printf("%d\n", res + 1);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll M = 1000000007;
int tbl[200001];
ll inv[200001];
ll calc(ll x){
  ll tmp = M-2;
  ll ret = 1;
  ll z = x;
  while(tmp){
    if(tmp&1)
      ret=(ret*z)%M;
    z=(z*z)%M;
    tmp/=2;
  }
  return ret;
}

int main(){
  int n;
  cin >> n;
  for(ll k=1;k<=200000;++k)
    inv[k]=calc(k);
  int i,j;    
  for(ll k=1;k<=n+1;++k){
    int a;
    cin>>a;
    if(!tbl[a])
      tbl[a]=k;
    else{
      i = tbl[a];
      j = k;
    }
  }
  
  ll x=n+1, y=1;
  for(ll k=1;k<=n+1;++k){
    if(k-1<=n+i-j)
      cout << (x-y+M)%M << endl;
    else
      cout << x << endl;
    x=(x*(n-k+1))%M;
    x=(x*inv[k+1])%M;
    y=(y*(n+i-j-k+1))%M;
    y=(y*inv[k])%M;
  }
  return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpl;
typedef vector<tuple<int, int, int>> vti;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    string ans = "No";
    for (int i=1;i<10;i++){
        for (int j=1;j<10;j++){
            if (n == i*j){
                ans = "Yes";
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
a = []
f = True
A = map(int, input().split())

for i in A:
    if i < 0:
        f ^= 1
    a.append(abs(i))

a.sort()

ans = sum(a[1:])

print(ans + (a[0] if f else -a[0]))


Measured memory_bytes: 15180
def min n,m
  if n > m
    return m
  else
    return n
  end
end
table = Array.new(100100,10000)
n = gets.to_i
table[0] = 0
for i in 1..n do
  table[i] = table[i-1] + 1
  if i >= 6
    table[i] = min(table[i-6] + 1,table[i])
  end
  if i >= 36
    table[i] = min(table[i-36] + 1,table[i])
  end
  if i >= 216
    table[i] = min(table[i-216] + 1,table[i])
  end
  if i >= 1296
    table[i] = min(table[i-1296] + 1,table[i])
  end
  if i >= 7776
    table[i] = min(table[i-7776] + 1,table[i])
  end
  if i >= 46656
    table[i] = min(table[i-46656] + 1,table[i])
  end
  if i >= 46656
    table[i] = min(table[i-46656] + 1,table[i])
  end
  if i >= 9
    table[i] = min(table[i-9] + 1,table[i])
  end
  if i >= 81
    table[i] = min(table[i-81] + 1,table[i])
  end
  if i >= 729
    table[i] = min(table[i-729] + 1,table[i])
  end
  if i >= 6561
    table[i] = min(table[i-6561] + 1,table[i])
  end
  if i >= 59049
    table[i] = min(table[i-59049] + 1,table[i])
  end
end
puts table[n].to_s

Measured memory_bytes: 2556
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    int a[n+1],b[n+1],c[n+1];
    rep(i,1,n+1)cin>>a[i];
    rep(i,1,n+1)cin>>b[i];
    rep(i,1,n)cin>>c[i];
    vector<pii> v;
    rep(i,1,n+1){
        v.push_back({a[i],i});
    }
    sort(v.begin(),v.end());
    int ans=0;
    int pas=-1;
    rep(i,1,n+1){
        int now=a[i];
        ans+=b[now];
        if(pas==now-1)ans+=c[now-1];
        pas=now;
    }
    cout<<ans<<endl;
}


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

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

    int N;
    cin >> N;

    int mx = 0, sum = 0;

    vector<int> p(N);
    for (int i=0; i<N; ++i) {
        cin >> p[i];
        mx = max(mx, p[i]);
        sum += p[i];
    }

    cout << sum - mx / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
s = input()
t = input()


def registration(s, t):

    first = len(s)
    last = len(t)

    if last - first != 1:
        print("No")
        return

    size = min(first, last)

    for i in range(size):
        if s[i] != t[i]:
            print("No")
            return

    print("Yes")

registration(s, t)


Measured memory_bytes: 9044
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

lint w[105], v[105];

void solveSingleCase(int caseNo)
{
    int N, W;
    cin >> N >> W;
    VEC(int) items[4];
    FOR(i, 0, N) {
        cin >> w[i] >> v[i];
        items[w[i] - w[0]].PB(v[i]);
    }

    VEC(int) acc[4];
    FOR(i, 0, 4) {
        sort(ALL(items[i]), greater<int>());
        acc[i].PB(0);
        FOR(j, 0, SZ(items[i])) {
            acc[i].PB(acc[i].back() + items[i][j]);
        }
    }

    int ret = 0;
    FOR(a, 0, SZ(acc[0]))
        FOR(b, 0, SZ(acc[1]))
            FOR(c, 0, SZ(acc[2])) {
                lint weight = a * 1LL * w[0] + b * 1LL * (w[0] + 1);
                weight += c * 1LL * (w[0] + 2);
                if (weight <= W) {
                    lint rem = W - weight;
                    int take = (int)(rem / (w[0] + 3));
                    take = min(take, SZ(acc[3]) - 1);
                    ret = max(ret, acc[0][a] + acc[1][b] + acc[2][c] + 
                                acc[3][take]);
                }
            }

    cout << ret << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 256
require 'prime'
N = gets.to_i
M = 10**9 + 7
h = Hash.new{0}
(1..N).each do |i|
  Prime.prime_division(i).each do |j, k|
    h[j] += k
  end
end
v = 1
h.each do |j, k|
  v *= k + 1
  v %= M
end
puts v


Measured memory_bytes: 2300
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807;
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
#define bool    _Bool
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }



int main() {
	int A, B;
	scanf("%d%d", &A, &B);

	int n = B - A + 1;
	int cnt = 0;
	//zero
	for (int i = 0; i < n; i++) {
		if (A + i == 0) {
			puts("Zero");
			return 0;
		}
		if (A + i < 0) {
			cnt++;
		}
	}

	if (cnt % 2) {
		puts("Negative");
	}
	else {
		puts("Positive");
	}




#ifdef DEBUGF
	getch();
#endif
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <complex>
using namespace std;
#ifdef DEBUGRUN
#define log(a) (cerr<<#a"="<<a<<endl)
#else
#define log(a) ((void)0)
#endif
#define rep(i, n) for(int i=0; i<(int)(n); i++)
typedef long long Int;
typedef complex<double> P;
const double EPS = 1e-8;

double sq(double a) { return a*a; }
double cross(const P& a, const P& b) { return imag(conj(a)*b); }
double dot(const P& a, const P& b) { return real(conj(a)*b); }
int ccw(const P& a, P b, P c) {
    b -= a, c -= a;
    if(cross(b, c)>0) return 1;
    if(cross(b, c)<0) return -1;
    if(dot(b, c)<0) return 2;
    if(norm(b)<norm(c)) return -2;
    return 0;
}
bool crossing(const P& l0, const P& l1, const P& m0, const P& m1) {
    return ccw(m0, m1, l0)*ccw(m0, m1, l1)<=0
        && ccw(l0, l1, m0)*ccw(l0, l1, m1)<=0;
}
P projection(const P& l0, const P& l1, const P& p) {
    double t = dot(p-l0, l0-l1) / norm(l0-l1);
    return l0 + t*(l0-l1);
}
bool intersectSP(const P& s0, const P& s1, const P& p) {
    return abs(s0-p)+abs(s1-p)-abs(s1-s0)<EPS;
}
double distanceSP(const P& s0, const P& s1, const P& p) {
    const P r(projection(s0, s1, p));
    if(intersectSP(s0, s1, r)) return abs(r-p);
    return min(abs(s0-p), abs(s1-p));
}
double distanceSS(const P& s0, const P& s1, const P& t0, const P& t1) {
    if(crossing(s0, s1, t0, t1)) return 0;
    return min(min(distanceSP(s0, s1, t0), distanceSP(s0, s1, t1)),
               min(distanceSP(t0, t1, s0), distanceSP(t0, t1, s1)));
}

int n, sx, sy, ex, ey;
int xa[100], ya[100], xb[100], yb[100], h[100];
P sp, ep, ps[100][4];

bool check() {
    rep(i, n) {
        rep(j, 4) {
            if(crossing(sp, ep, ps[i][j], ps[i][(j+1)%4])) return false;
        }
        if(crossing(sp, ep, ps[i][0], ps[i][2])) return false;
        if(crossing(sp, ep, ps[i][1], ps[i][3])) return false;
        if(xa[i]<=sx && sx<=xb[i] && ya[i]<=sy && sy<=yb[i]) return false;
        if(xa[i]<=ex && ex<=xb[i] && ya[i]<=ey && ey<=yb[i]) return false;
    }
    return true;
}

bool can(double r) {
    rep(i, n) {
        const double lim = h[i]>=r ? r : sqrt(sq(r)-sq(r-h[i]));
        rep(j, 4) {
            if(distanceSS(sp, ep, ps[i][j], ps[i][(j+1)%4])<lim) return false;
        }
    }
    return true;
}

int main() {
    for(;;) {
        scanf("%d", &n);
        if(n==0) return 0;
        scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
        rep(i, n) scanf("%d%d%d%d%d", xa+i, ya+i, xb+i, yb+i, h+i);
        sp = P(sx, sy);
        ep = P(ex, ey);
        rep(i, n) {
            ps[i][0] = P(xa[i], ya[i]);
            ps[i][1] = P(xa[i], yb[i]);
            ps[i][2] = P(xb[i], yb[i]);
            ps[i][3] = P(xb[i], ya[i]);
        }
        double ans = 0;
        if(check()) {
            log(true);
            double l=0, r=1000;
            rep(_, 200) {
                const double mid=(l+r)/2;
                if(can(mid)) l=mid;
                else r=mid;
            }
            ans = l;
        }
        printf("%.9f\n", ans);
    }
}

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

int main(void){
    int n,flag=0;
    string str[101];
    cin >> n;
    cin >> str[0];
    for(int i=1;i<n;i++){
        cin >> str[i];
        for(int j=0;j<i;j++){

            if(str[i]==str[j]){
                flag=1;
            }
        }
        if(str[i][0]!=str[i-1][str[i-1].length()-1]){
            flag=1;
        }
    }
    if(flag){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

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

int main()
{
    
    int bingo[3][3];
    bool bin[3][3];

    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> bingo[i][j];
            bin[i][j] = false;
        }
        
    }
    
    int n;
    cin >> n;
    
    vector<int> b(n);
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }

    for(int i = 0; i < 3; i++){
        
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < n; k++)
            {
                if(bingo[i][j] == b[k]) bin[i][j] = true;
            }
            
        }
        
    }

    bool ans = false;

    if(bin[0][0] && bin[0][1] && bin[0][2]) ans = true;
    if(bin[1][0] && bin[1][1] && bin[1][2]) ans = true;
    if(bin[2][0] && bin[2][1] && bin[2][2]) ans = true;
    if(bin[0][0] && bin[1][0] && bin[2][0]) ans = true;
    if(bin[0][1] && bin[1][1] && bin[2][1]) ans = true;
    if(bin[0][2] && bin[1][2] && bin[2][2]) ans = true;
    if(bin[0][0] && bin[1][1] && bin[2][2]) ans = true;
    if(bin[0][2] && bin[1][1] && bin[2][0]) ans = true;
    
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;

}

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

int n,m;
int l[1000000];
int dp[1000000];
main()
{
    cin>>n>>m;
    fill(dp,dp+n+1,1e9);
    for(int i=1;i<=n;i++){
        cin>>l[i];
    }
    dp[1]=0;
    dp[2]=abs(l[2]-l[1]);
    for(int i=3;i<=n;i++){
        for(int j=i-1;j>=i-m;j--){
            if(j<0)break;;
            dp[i]=min(dp[i],dp[j]+abs(l[j]-l[i]));//cout<<j<<" ";
        }//cout<<dp[i];
        //cout<<"\n";
    }
    cout<<dp[n];
}


Measured memory_bytes: 4736
A, B, C = map(int, input().split())
K = int(input())
flag = 0

for i in range(K):
    if B <= A:
        B *= 2
    else:
        if C <= B:
            C *= 2
        else:
            pass
    if A < B < C:
        flag = 1
        
if flag:
    print('Yes')
else:
    print('No')


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

#define ll long long


int main()
{
    ll n;

    cin >> n;

    ll sq = sqrt(n);

    ll count = 0;



    vector<ll>v;


    for(int i=1; i<=sq; i++)
    {
       if(n%i==0)
       {
           v.push_back(i+(n/i));
       }
    }

    sort(v.begin(),v.end());


    cout << v[0]-2 << endl;

}


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


class Solver
{
private:
	int n;
	int customer[130] = {};
	bool Input()
	{
		cin >> n;
		if (n == 0)return false;
		for (int i = 0; i < n; i++)
		{
			int a;
			cin >> a;
			customer[a]++;
		}
		return true;
	}
	//[min,max]
	int NumOfCustomers(int min, int max)
	{
		int num = 0;
		for (int i = min; i <= max; i++)
		{
			num += customer[i];
		}
		return num;
	}

	void Output()
	{
		for (int i = 0; i <= 5; i++)
		{
			cout << NumOfCustomers(10 * i, 10 * i + 9) << endl;
		}
		cout << NumOfCustomers(60,120) << endl;
	}

public:
	bool Solve()
	{
		if (Input())
		{
			Output();
			return true;
		}
		else return false;
	}
};

int main()
{
	while(Solver().Solve());
}



Measured memory_bytes: 3104
#include <iostream>
#include <stdio.h>
using namespace std;
 
int main(){
	int h,w,i,j;
	while (1) {
		cin >> h >> w;
		if (h==0&&w==0) {
			break;
		}
		
		for (j=0;j<w;j++){
			cout << "#";
		}
		cout << endl;
		
		for (i=1;i<h-1;i++) {
			cout << "#";
			for (j=1;j<w-1;j++) {
				cout << ".";
			}
			cout << "#" << endl;
		}
		for (j=0;j<w;j++){
			cout << "#";
		}
		cout << endl;
		cout << endl;
	}
    return 0;
}

Measured memory_bytes: 1152
n=int(input())
l=list(map(int,input().split()))
l.sort()
sumA=0
sumB=0
for i in range(1,n+1):
  if i%2==1:
    sumA+=l[(-1)*i]
  else:
    sumB+=l[(-1)*i]
print(sumA-sumB)

Measured memory_bytes: 3064
n,m = map(int, input().split())
l = []
for _ in range(m):
    data = list(map(int,input().split()))
    l.append(data)
p = list(map(int, input().split()))

ans=0
for i in range(2 ** n):
    swi = []
    for j in range(n):
        if ((i >> j) & 1):
            swi.append(1)
        else:
            swi.append(0)
    swi.reverse()

    ok_flag=True
    for lit in range(m):
        sm=0
        for tmp in range(1,len(l[lit])):
            sm += swi[l[lit][tmp]-1]
        if sm % 2 != p[lit]:
            ok_flag=False

    if ok_flag:
        ans+=1
print(ans)

Measured memory_bytes: 3064
import java.util.*;


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

        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.nextLine());
        int incremental = sc.nextInt();

        int sum = 1;

        for (int i = 0; i < num; i++) {
            if ( sum * 2 < sum + incremental) {
                sum *= 2;
            }else {
                sum += incremental;
            }
        }

        System.out.println(sum);

    }
}

Measured memory_bytes: 20436
n, W = map(int, input().split())
w = [0] * n
v = [0] * n
for i in range(n):
    w[i], v[i] = map(int, input().split())

INF = 10**10

dp = [[INF for i in range(100010)] for j in range(n+1) ]

dp[0][0] = 0

for i in range(n):
    for j in range(100010):
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])
        if j>=v[i]:
            dp[i+1][j] = min(dp[i][j-v[i]]+w[i], dp[i+1][j])

for j in range(100010):
    if dp[n][100009-j] <= W:
        print(100009-j)
        break

Measured memory_bytes: 218028
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, C, K;
    cin >> N >> C >> K;
    int T[100000];
    for(int i=0;i<N;i++)
        cin >> T[i];
    
    // 昇順ソート
    sort(T, T + N);
    // 最も先に到着した客が怒り出す時刻, 現在の乗客, 発車本数
    int previous = 0, cap = 0, ans = 0;
    for(int i=0;i<N;i++){
        if(previous == 0)
            previous = T[i] + K;
        if(previous < T[i]){
            ans++;
            previous = T[i] + K;
            cap = 0;
        }        
        cap++;
        if(cap == C){
            ans++;
            previous = 0;
            cap = 0;
        }
    }

    if(cap != 0)
        ans++;

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

Measured memory_bytes: 640
N, *h = map(int, open(0).read().split())
cost = [float('inf') for _ in h]
for i, step_h in enumerate(h):
    if i == 0:
        cost[0] = 0
    else:
        # その足場に進むためのコストを計算
        st1 = st2 = float('inf')
        st1 = abs(h[i-1]-step_h) + cost[i-1]
        if i >= 2:
            st2 = abs(h[i-2]-step_h) + cost[i-2]
        # コストを更新
        update_cost = st1 if st1 < st2 else st2
        if update_cost < cost[i]:
            cost[i] = update_cost
print(cost[N-1])

Measured memory_bytes: 13876
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

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

int main() {
    int N, A;
    cin >> N >> A;
    vector<int> x(N);
    int maximum = A;
    rep(i,N) {
        cin >> x[i];
        maximum = max(A, x[i]);
        x[i] -= A;
    }
    sort(x.begin(), x.end());

    long long dp[N + 1][2 * N * maximum + 1];
    rep(i,2*N*maximum+1) dp[0][i] = (i == N * maximum ? 1 : 0);
    rep(i,N) {
        rep(j,2*N*maximum+1) {
            if (j - x[i] < 0 || j - x[i] > 2 * N * maximum) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = dp[i][j] + dp[i][j - x[i]];
        }
    }

    cout << dp[N][N * maximum] - 1 << endl;

    return 0;
}

Measured memory_bytes: 2176
a=[input().split() for i in range(3)]
n=int(input())
b=[int(input()) for i in range(n)]
for i in range(3):
    for j in range(3):
        if int(a[i][j]) in b:
            a[i][j]=999
#印をつける
c=0
for i in range(3):
    if a[i][0]==999 and a[i][1]==999 and a[i][2]==999:
        c+=1
        break
    elif a[0][i]==999 and a[1][i]==999 and a[2][i]==999:
        c+=10
        break
    elif a[0][0]==999 and a[1][1]==999 and a[2][2]==999:
        c+=100
        break
    elif a[0][2]==999 and a[1][1]==999 and a[2][0]==999:
        c+=1000
        break
if c==0:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using namespace std;

//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------


int main() {
  ll n,w;
  cin>>n>>w;
  vll a(n+1),b(n+1);
  vvll dp(n+1,vll(100001,0));
  
  rep(i,n)cin>>a.at(i+1)>>b.at(i+1);
    
    rep(i,n){
        rep(j,w+1){
            if(j>=b.at(i+1)){
                dp.at(i+1).at(j)=max(dp.at(i).at(j-b.at(i+1))+a.at(i+1),dp.at(i).at(j));
            }else{
                dp.at(i+1).at(j)=dp.at(i).at(j);
            }
        }
    }
    
 
 
  cout<<dp.at(n).at(w)<<endl;
  
  
}



Measured memory_bytes: 82808
#include<iostream>
#include<vector>
#include<functional>
#include<climits>
using namespace std;

template<typename T>
struct Seg{
private:
    vector<T> node;
    int n;
    function<T(T,T)> f;
    T def;

public:
    Seg(int siz, T d, function<T(T,T)> f) : def(d), f(f) {
        n = 1;
        while(n < siz)  n *= 2;
        node.resize(2*n-1, def);
    }
    Seg(vector<T> v, T d, function<T(T,T)> f) : def(d), f(f){
        n = 1;
        while(n < v.size())  n *= 2;
        node.resize(2*n-1);
        for(int i = 0; i < v.size(); i++)   node[n-1+i] = v[i];
        for(int i = n-2; i >= 0; i--)   node[i] = f(node[2*i+1], node[2*i+2]);
    }

    void update(int x, T val){
        x += n-1;
        node[x] = f(node[x], val); /* ! */
        while(x){
            x = (x-1)/2;
            node[x] = f(node[2*x+1], node[2*x+2]);
        }
    }

    T query(int a, int b){
        int L = a+n-1, R = b+n-1;
        T ret = def;
        while(L < R){
            if((R&1) == 0)  ret = f(ret, node[--R]);
            if((L&1) == 0)  ret = f(ret, node[L++]);
            L >>= 1, R >>= 1;
        }
        return ret;
    }
};

vector<int> v[200000], et;
int be[200000], en[200000], k = 0;

void dfs(int x, int p){
    be[x] = k++;
    et.push_back(x);
    for(int j : v[x]){
        if(j != p){
            dfs(j, x);
            et.push_back(x);
            k++;
        }
    }
    en[x] = k;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int k;  cin >> k;
        while(k--){
            int x;  cin >> x;
            v[i].push_back(x);
        }
    }
    dfs(0, -1);
    Seg<int> stsum(et.size(), 0, [](int x, int y){return x+y;});
    int q;
    cin >> q;
    while(q--){
        int op, a, b;
        cin >> op >> a;
        if(op == 0){
            cin >> b;
            stsum.update(be[a]-1, b);
            stsum.update(en[a], -b);
        }else{
            cout << stsum.query(0, be[a]) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 19040
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    int n;
    cin >> n;
    if(n>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
#include <math.h>
#include <stdio.h>
#include <vector>
#define pai 3.1415926535
using namespace std;

int main() {

	int a;
	int b;
	while (true) {
		cin >> a >> b;
		if (a == 0 && b == 0) break;
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				int c = j + i;
				if (c % 2 == 0) printf("#");
				else {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	

	return 0;
}


Measured memory_bytes: 3084
using System;
class A{
  static void Main(){
    var s = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
    if(s[0]==1) s[0]+=13;
    if(s[1]==1) s[1]+=13;
    Console.WriteLine(s[0]==s[1]?"Draw":s[0]>s[1]?"Alice":"Bob");
  }
}


Measured memory_bytes: 13140
import java.util.*;

public class Main {
    // Your code here!
    
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        // String a = "1 2";
        String line = scan.nextLine();
        String[] input = line.split(" ");
        int x = Integer.valueOf(input[0]);
        int y = Integer.valueOf(input[1]);
        int round = 2 * (x + y);
        int dense = x * y;
        System.out.println(String.valueOf(dense) + " " + String.valueOf(round));
    }
}



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

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

  for(int i=0; i < n; i++) {
    int cnt = 0;
    for(int j=i; j < n; j++) {
      char c = s[j];
      if (c == 'A' || c == 'C' || c == 'G' || c == 'T') cnt++;
      else break;
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    unsigned long h;
    cin >> h;
    h /= 2;
    unsigned long sum = 1,count = 1;
    while(h != 0){
        h /= 2;
        sum += count*2;
        count *= 2;
    }
    cout << sum << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  sort(a.rbegin(),a.rend());
  
  ll ans = 0;
  int t = n-1;
  rep(i,n) {
    int lim = 2;
    if(i == 0) lim = 1;
    
    rep(j,lim){
      if(t > 0) {
      ans += a.at(i);
      t--;
      }
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3996
import java.util.Scanner;
import java.util.Arrays;

class Main {
  public static void main(String[] args){
    Scanner cin = new Scanner(System.in);
    MyArray myArray = new MyArray(10);
    
    for (int i = 0; i < 10; i++){
      myArray.input(cin.nextInt());
    }
    myArray.sort();
    for (int i = 0; i < 3; i++){
      System.out.println(myArray.top());
      myArray.pop();
    }
  }
}

class MyArray {
  private int num[];
  private int size = 0;
  
  MyArray(int n){
    this.num = new int[n];
  }

  protected void sort(){
    Arrays.sort(num);
  }

  protected int top(){
    if (size == 0) {
//      System.out.println("empty");
      return (0);
    }
    return (num[size - 1]);
  }

  protected void pop(){
    for (int i = size - 1; i > 1; i--){
      num[i] = num[i - 1];
    }
  }

  protected void input(int n){
    num[size] = n;
    size++;
  }

  protected int at(int n){
    return (num[n]);
  }
}

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

int main() {
  int N;
  scanf("%d", &N);
  int ans = 1;
  while (1) {
    if (pow(ans, 2) > N) {
      break;
    } else {
      ans++;
    }
  }
  printf("%d", (int)pow(ans - 1, 2));
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
long long gcd(long long a, long long b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}
 
/*  lcm (a, b) : 2整数版
    入力：整数 a, b
    出力：aとbの最小公倍数
*/
long long lcm(long long a, long long b) {
    long long d = gcd(a, b);
    return a / d * b;
}
int main() {
    ll a, b;
    cin >> a >> b;
    cout << lcm(a, b) << endl;
    return 0;
}


Measured memory_bytes: 3576
# ABC124C - Coloring Colorfully
def main():
    s = input()
    a, ans = s[0], 0
    for i, j in enumerate(s):
        if (i % 2 and j == a) or (not i % 2 and j != a):
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> p;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    string S;
    cin >> N >> S;

    int ans = 0;

    int x = 0;

    for(int i = 0; i < N; i++) {
        if(S[i] == 'I') x++;
        else x--;
        ans = max(ans, x);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
def main():  
    def cmb(n, r, mod):
            if ( r<0 or r>n ):
                return 0
            r = min(r, n-r)
            return g1[n] * g2[r] * g2[n-r] % mod
    x,y = map(int,input().split())
    d = x + y
    if d%3 == 0:
        a = (2*x-y)//3
        b = (2*y-x)//3
        
        mod = 10**9+7
        N = 10**6
        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]        
        for i in range( 2, N + 1 ):
            g1.append( ( g1[-1] * i ) % mod )
            inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
            g2.append( (g2[-1] * inverse[-1]) % mod )
        
        ans = cmb(a+b,a,mod)
        print(ans)
    else:
        print(0)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 128452
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void calc(string s, int k) {
    auto cs = new char[s.length];
    for (int i = 0; i < s.length; i++) {
        cs[i] = s[i] != s[k - 1] ? '*' : s[i];
    }
    writeln(cs);
}

void main() {
    readint;
    string s = read!string;
    int k = readint;
    calc(s, k);
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;
	int a[110];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	long long cost=0, ans=1e9;
	for (int o = -100; o <= 100; o++) {
		for (int i = 0; i < n; i++) {
			cost += pow(a[i] - o, 2);
		}
		ans = min(ans, cost);
		cost = 0;
	}
	cout << ans << endl;
}

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

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


bool table[55][55];

struct state{
	int tx;
	int ty;
	int kx;
	int ky;
	int t;
};

int x,y;
int tx,ty;
int kx,ky;

bool check(int cx,int dx,int cy,int dy){
	if(0<=cx+dx&&cx+dx<x&&0<=cy+dy&&cy+dy<y&&(!table[cx+dx][cy+dy]))
		return true;
	else
		return false;
}

bool visited[55][55][55][55];


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


int bfs(void){
	rep(i,55)rep(j,55)rep(k,55)rep(l,55) visited[i][j][k][l]=false;
	state init;
	init.tx=tx;init.ty=ty;
	init.kx=kx;init.ky=ky;
	init.t=0;
	queue<state> q;

	q.push(init);
	visited[init.tx][init.ty][init.kx][init.ky]=true;

	while(!q.empty()){
	//	cout << "check" << endl;
		state cur=q.front();q.pop();
		if(cur.tx==cur.kx&&cur.ty==cur.ky)
			return cur.t;

		if(cur.t>=100)
			continue;
	//	cout << "check" << endl;
		rep(i,4){
			state next=cur;
			if(check(cur.tx,dx[i],cur.ty,dy[i])){
				next.tx+=dx[i];
				next.ty+=dy[i];
			}
			if(check(cur.kx,dx[(i+2)%4],cur.ky,dy[(i+2)%4])){
				next.kx+=dx[(i+2)%4];
				next.ky+=dy[(i+2)%4];
			}
			next.t++;
			if(!visited[next.tx][next.ty][next.kx][next.ky]){
				visited[next.tx][next.ty][next.kx][next.ky]=true;
				q.push(next);
			}
		//	cout << next.tx << " " << next.ty << endl; 
		//	cout << "check" << endl;
		}
	}
	return -1;
}

int main(void){
	
	while(cin >> x >> y,x|y){
		
		cin >> tx >> ty;
		cin >> kx >> ky;
		tx--;ty--;kx--;ky--;
		rep(i,y)rep(j,x) cin >> table[j][i];
		int res=bfs();
		if(res==-1)
			cout << "NA" << endl;
		else
			cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 10308
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define vi vector<int>
using namespace std;

//int gcd(int a, int b){
//	return b==0 ? a : gcd(b, a%b);
//}

int32_t main(void){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	
	double t;
	cin>>t;
	double ans = (t/3);
	ans = ans*ans*ans;
	cout<<fixed<<setprecision(12)<<ans;
}

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

using namespace std;
typedef long long ll;

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

    ll a=-1;
    ll ans=0;
    ll anss =0;
    ll x=0;
    ll count=0;
    ll i,j;
    vector<ll> b;


    string N;
    cin>>N;


//b.push_back();
   ll z[11];
for(i=0;i<11;i++){
    z[i]=0;
}
int flag=0;

for(i=0;i<N.length();i++){
    if(N[i]=='A' || N[i]=='T' ||N[i]=='C' ||N[i]=='G'){
        if(flag==0){
            b.push_back(i);
            a++;
            z[a]++;
            
        }else{
            z[a]++;
           
        }

        flag=1;
    }else{
        flag=0;
    }
}
int max=0;
int max_num;
for(i=0;i<=a;i++){
    if(z[i]>max){
        max=z[i];
        max_num=i;
    }
}

    cout << max << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
		public static void main(String[] args){
			Scanner scan = new Scanner(System.in);
			while(true){
				int s=1000000;
				int n;
				n= scan.nextInt();
				if(n==0){
					break;
				}
				int[] a = new int[n];
				for(int i=0;i<n;i++){
					a[i]=scan.nextInt();
				}
				Arrays.sort(a);
				for(int i=1;i<n;i++){
					int h=0;
						h = a[i]-a[i-1];
						if(h<s){
							s=h;
						}
				}
				System.out.println(s);
			}
		}
}



Measured memory_bytes: 46884
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[605050], b[605050];
ll s0[605050], s1[605050], s2[605050];
ll dp[605050];
ll calc(ll s, ll t)
{
	ll r1 = -(s2[t + 1] - s2[s]) + (s + t)*(s1[t + 1] - s1[s]) - s*t*(s0[t + 1] - s0[s]);
	ll r2 = (t - s)*(a[s] + a[t]);
	return -r1 * 2 + r2;
}
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)scanf("%lld", &a[i]), a[num + i] = a[num + num + i] = a[i];
	for (int i = 0; i < num; i++)scanf("%lld", &b[i]), b[num + i] = b[num + num + i] = b[i];
	ll maxi = -1, rr = -1;
	for (int i = 0; i < num; i++)if (maxi < a[i])maxi = a[i], rr = i;
	for (int i = 0; i < num + num + num; i++)s0[i + 1] = s0[i] + b[i], s1[i + 1] = s1[i] + b[i] * i, s2[i + 1] = s2[i] + b[i] * i * i;
	vector<int>idx;
	idx.push_back(rr);
	for (int i = rr + 1; i <= rr + num; i++)
	{
		for (;;)
		{
			if (idx.size() <= 1)break;
			int x1 = idx[idx.size() - 1], x2 = idx[idx.size() - 2];
			if (dp[x1] + calc(x1, i) <= dp[x2] + calc(x2, i))idx.pop_back();
			else break;
		}
		int x = idx[idx.size() - 1];
		dp[i] = dp[x] + calc(x, i), idx.push_back(i);
		//printf("%d %lld\n", i, dp[i]);
	}
	printf("%.20lf\n", double(dp[rr + num]) / (num + num));
}

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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 650555;
const int L = 21;
const int M = 2155;
const int K = 555;

void solve() {
    int k;
    cin >> k;

    ll sum = 0;
    for (int a = 1; a <= k; a++){
        for (int b = 1; b <= k; b++){
            for (int c = 1; c <= k; c++){
                sum += GCD(GCD(a,b), c);
            }
        }
    }

    cout << sum;

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3648
#include <cstdio>

int n, m, s, g1, g2;
int d[128][128];

int inf = (1 << 29);

#include <algorithm>
bool load() {
  for(int i = 0; i < 128; ++i) {
    for(int j = 0; j < 128; ++j) {
      d[i][j] = inf;
    }
    d[i][i] = 0;
  }
  scanf("%d %d %d %d %d", &n, &m, &s, &g1, &g2);
  if( n == 0 ) return false;
  for(int i = 0; i < m; ++i) {
    int x, y, w;
    scanf("%d %d %d", &x, &y, &w);
    d[x][y] = w;
  }
  return true;
}

void solve() {
  for(int k = 1; k <= n; ++k) {
    for(int i = 1; i <= n; ++i) {
      for(int j = 1; j <= n; ++j) {
        d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int res = inf;
  for(int i = 1; i <= n; ++i) {
    res = std::min(res, d[s][i] + d[i][g1] + d[i][g2]);
  }
  printf("%d\n", res);
}

int main() {
  while( load() ) solve();
  return 0;
}

Measured memory_bytes: 2752
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

vector<int64> vv;

void make(int64 bb, int64 dd)
{
	if(dd == 11)
	{
		return;
	}
	if(bb == -1)
	{
		for(int64 ii = 1;ii < 10;ii++)
		{
			vv.push_back(ii);
			make(ii, dd);
		}
		return;
	}
	int64 aa = bb % 10;
	bb *= 10;
	if(aa != 0)
	{
		vv.push_back(bb + aa - 1);
		make(bb + aa - 1, dd + 1);
	}
	vv.push_back(bb + aa);
	make(bb + aa, dd + 1);
	if(aa != 9)
	{
		vv.push_back(bb + aa + 1);
		make(bb + aa + 1, dd + 1);
	}
	return;
}

int main()
{
	int64 kk;
	cin >> kk;
	make(-1, 1);
	sort(vv.begin(), vv.end());
	cout << vv[kk - 1] << endl;
	return 0;
}

Measured memory_bytes: 11556
fun main(args: Array<String>) {
    fun next() = readLine()!!
    val S = next().map { it - '0' }
    fun count(v: List<Int>, d: Int) = v.withIndex().sumBy { if (it.index % 2 == d) it.value else 1 - it.value }
    println(Math.min(count(S, 0), count(S, 1)))
}

Measured memory_bytes: 38888
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    int sum=0, mean=0;
    vector<int> vec(n);
    rep(i, n){
        cin >> vec[i];
        sum += vec[i];
    }
    mean = (double)sum / (double)n + 0.5;
    int diff=0;
    rep(i, n){
        diff += pow(abs(vec[i] - mean), 2);
    }
    out(diff);


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long 
#define speedrap ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int be(int a,int b,int mod) {if(b == 0) return 1; if(b%2 == 1) return (a*be(a,b-1,mod))%mod; else return (be(a,b/2,mod)*be(a,b/2,mod))%mod;}
const int mod = 2019;
#define PI 3.14159265359
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcount
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
#define mkp(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
const int siz = 2*(1e5 + 1);
const int logi = 21;
const double epsilon = 1e-6;
int prime[siz];
bool cmp(const int &a,const int &b)
{
  return (abs(a-b)>1);
}


signed main()
{
	#ifndef ONLINE_JUDGE
 	freopen("in.txt", "r", stdin);
 	freopen("out.txt", "w", stdout);
 	#else
// // online submission
 	#endif 
	speedrap
	int t;
	t = 1;
	//cin>>t;
	while(t--)
	{
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		int flag = 1;
		int cnt = 0;
		while(true)
		{
			cnt++;

			if(cnt %2 == 1)
			{
				c -= b;
			}
			else
			{
				a -= d;
			}
			if(a <= 0 and c > 0)
			{
				flag = 2;
				break;
			}

			if(a > 0  and c <= 0)
			{
				flag = 1 ;
				break;
			}
			
			
		}

		if(flag == 1)
		{
			cout<<"Yes\n";
		}
		else
		{
			cout<<"No\n";
		}
	}
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;

queue<long long> q;

long long lunlunnum(int k){
    REP(i,9){
        q.push(i);
    }
    for(int i=0;i<k-1;i++){
        long long x=q.front();
        long long r=x%10;
        if(r!=0){
         q.push(10*x+r-1);
        }
        q.push(10*x+r);
        if(r!=9){
         q.push(x*10+r+1);
        }   
        q.pop();
    }
    return q.front();
}


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

    cout << lunlunnum(k) << endl;

}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main() {
    int N,M; cin>>N>>M;
    f64 ans = 0;
    f64 res = 1;
    FOR(i,1,100000) {
        ans += (1900*M+max(N-M,0)*100)*res*pow(2,-M)*i;
        res -= res*pow(2,-M);
    }
    cout<<round(ans)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
#define endl '\n'
#define F first
#define S second
const int MAX_N=1e2+2;
const int MAX_W=1e5+5;

int n,W;
int w[MAX_N], v[MAX_N];
ll dp[MAX_N][MAX_W];
ll ans;

int main()
{
	scanf("%d%d",&n,&W);
	for(int i=1;i<=n;i++) scanf("%d%d",&w[i],&v[i]);
	for(int i=1;i<=n;i++) for(int j=0;j<=W;j++)
		if(j-w[i]>=0) dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
		else dp[i][j]=max(dp[i][j],dp[i-1][j]);
	for(int i=0;i<=W;i++) ans=max(ans,dp[n][i]);
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 78336
using static System.Console;
using static System.Convert;

class Program
{
    static void Main(string[] args)
    {
        var input = ReadLine().Split(' ');
        var firstX = ToInt32(input[0]);
        var firstY = ToInt32(input[1]);
        var num = ToInt32(input[2]);

        var startX = 0;
        var startY = 0;
        var endX = firstX;
        var endY = firstY;
        for(var i = 0; i < num; i++)
        {
            var input2 = ReadLine().Split(' ');
            var x = ToInt32(input2[0]);
            var y = ToInt32(input2[1]);
            switch (ToInt32(input2[2]))
            {
                case 1:
                    if(startX<x)
                    startX =x;
                    break;
                case 2:
                    if(endX>x)
                    endX = x;
                    break;
                case 3:
                    if(startY<y)
                    startY=y;
                    break;
                case 4:
                    if(endY>y)
                    endY = y;
                    break;
            }
        }
        var result = endX - startX>=0 && endY - startY >= 0 ? (endX - startX) * (endY - startY) : 0;
        WriteLine(result);
    }
}


Measured memory_bytes: 11220
#include <stdio.h>

int main(void)
{
	int a,b,c,temp;
	scanf("%d %d %d",&a,&b,&c);
	
	if(a>b){
		temp=a;
		a=b;
		b=temp;
	}
	if(b>c){
		temp=b;
		b=c;
		c=temp;
	}
	if(a>b){
		temp=a;
		a=b;
		b=temp;
	}
		
	
	printf("%d %d %d\n",a,b,c);
	
	return 0;
}
	
	

Measured memory_bytes: 596
#include<stdio.h>

int main(){
  long long n;
  long long k;
  long long cnt = 0;
  long long hoge;
  scanf("%lld %lld",&n,&k);
  if(k%2==1){
    cnt = (n / k)*(n / k)*(n / k);
  }else{
    hoge = (n / (k/2)) - (n / k);
    cnt = (n / k)*(n / k)*(n / k)+hoge*hoge*hoge;
  }
  printf("%lld",cnt);
  return 0;
}
    

Measured memory_bytes: 128
import collections
def prime_factorize(n):
    a = []
    while n%2 == 0:
        a.append(2)
        n//=2
    f =3
    while f*f <= n:
        if n%f == 0:
            a.append(f)
            n//=f
        else:
            f +=2
    if n != 1:
        a.append(n)
    return a

# N-1の約数を数える
N = int(input())
factor = collections.Counter(prime_factorize(N-1))
K = 1
for i in list(factor.values()):
    K *= i+1
K -=1
for f in range(2, int(N**0.5)+1):
    n = N
    if n%f != 0:
        continue
    while n%f ==0:
        n//=f
    if n%f ==1 or n==1:
        K+=1
#最後は自分自身を加える。
K +=1
print(K)

Measured memory_bytes: 3316