akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main() {
	int h, w; cin >> h >> w;
	vector<string> grid(h);
	rep(i, 0, h) cin >> grid[i];
	vector<vector<int>> a(h);
	rep(i, 0, h) a[i].resize(w, 0);
	rep(i, 0, h) {
		int idx = 0, cnt = 0;
		rep(j, 0, w) {
			if (grid[i][j] == '.') cnt++;
			else {
				rep(k, idx, j+1) a[i][k] += cnt;
				idx = j; cnt = 0;
			}
		}
		rep(k, idx, w) a[i][k] += cnt;
	}
	rep(j, 0, w) {
		int idx = 0, cnt = 0;
		rep(i, 0, h) {
			if (grid[i][j] == '.') cnt++;
			else {
				rep(k, idx, i + 1) a[k][j] += cnt;
				idx = i; cnt = 0;
			}
		}
		rep(k, idx, h) a[k][j] += cnt;
	}
	int ans = 0;
	rep(i, 0, h){
		rep(j, 0, w){
			if(grid[i][j]=='.') ans = max(ans, a[i][j]-1);
		}
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 20096
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>

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

int main() {
    ll d, t, s, ans;
    cin >> d >> t >> s;
    if (d <= s * t)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3120
#coding:utf-8

a, b, k = map(int, input().split())

if k <= a:
    a = a - k
elif a < k and k <= (a + b):
    b = b - (k - a)
    a = 0
elif (a + b) < k:
    a = 0
    b = 0

print(a, b)

Measured memory_bytes: 3060
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

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

  queue<string> q;
  unordered_map<string, int> m;
  REP(i, N) {
    string W;
    cin >> W;
    q.emplace(W);
    m[W]++;
  }
  if (any_of(ALL(m), [](const auto &p) { return p.second > 1; })) {
    cout << "No" << endl;
    return 0;
  }

  char t = '\0';
  while (!q.empty()) {
    const auto w = q.front();
    if (t != '\0' && t != w.front()) {
      cout << "No" << endl;
      return 0;
    }
    q.pop();
    t = w.back();
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

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

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

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

// 以下から
const int MAX_N = 100000;
struct Edge {
    int to;
    int id;
};

vector<vector<Edge>> g;
vector<int> ans;
const int MN = 15;
vector<int> searched(MN, 0);
vector<int> color(MN, -1);

int main() {
    int n; cin >> n;
    string s,t; cin >> s >> t;
    stringstream ss;
    rep(i,n) {
        ss << s[i] << t[i];
    }
   
    cout << ss.str() << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, n, ans;
  scanf("%lld", &n);
  ll a[n], b[n], c[n];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]), a[i]--;
  for(i = 0; i < n; ++i) scanf("%lld", &b[i]);
  for(i = 1; i < n; ++i) scanf("%lld", &c[i]);
  ans = b[a[0]];
  for(i = 1; i < n; ++i) {
    ans += b[a[i]];
    if(a[i] == a[i - 1] + 1) ans += c[a[i]];
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repp(i, n) for(int i = 1; i <= (int)(n); i++)
#define co(x) cout<<x<<endl
typedef long long int lint;
 
int main() {
  vector<int> X = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  co(X.at(K-1));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main() {
  int d, g;
  cin >> d >> g;
  vector<vector<int>> pc(d);
  rep(i, d) {
    int p, c;
    cin >> p >> c;
    pc[i] = {p, c};    
  }

  int ans = 10004;
  for (int bit = 0; bit < (1<<d); bit++) {
    int score = 0;
    int solved_num = 0;
    set<int> used;
    for (int i = 0; i < d; ++i) {
      if (bit & (1<<i)) { // 列挙に i が含まれるか
        used.insert(i);
        score += pc[i][0] * (i+1) * 100 + pc[i][1];
        solved_num += pc[i][0];
      }
    }
    int remain = max(0, g - score);
    // cout << "--------" << '\n';
    // cout << "remain" << remain << '\n';
    for (int i = d-1; i >= 0; i--) {
      auto itr = used.find(i);
      if (itr != used.end()) continue;
      int s = 100 * (i+1);
      int will_solve = ((remain + s - 1) / s);
      if (will_solve >= pc[i][0]) break;
      score += will_solve * s;
      solved_num += will_solve;
      // cout << i << "will" << will_solve << '\n';
      break;
    }
    // cout << "bit" << bit << '\n';
    // cout << score << ' ' <<  ans << ' ' << solved_num << '\n';
    if (score >= g) ans = min(solved_num, ans);
  }
  cout << ans << '\n';  
  return 0;
}

Measured memory_bytes: 3656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		long n = Long.parseLong(br.readLine());

		ArrayList<Long> list = divisor(n);

		long min = Long.MAX_VALUE;
		long ans = 0;

		for (int i = 0; i < list.size(); i += 2) {
			long a = list.get(i);
			long b = list.get(i + 1);

			if (a + b < min) {
				ans = (a - 1) + (b - 1);
			}
		}

		System.out.println(ans);
	}

	public static ArrayList<Long> divisor(long n) {
		final ArrayList<Long> list = new ArrayList<>();

		for (long i = 1; i * i <= n; i++) { // √n
			if (n % i == 0) {
				list.add(i);
				list.add(n / i);
			}
		}
		return list;
	}
}


Measured memory_bytes: 22484
x,n=map(int,input().split())
if n==0:
  print(x)
else:
	a=list(map(int,input().split()))
	box=[0]*101
	for i in a:
		if -50<= i-x <=50:
			box[50+i-x]=1
	for i in range(51):
		if box[50-i]==0:
			print(x-i)
			break
		elif box[50+i]==0:
			print(x+i)
			break


Measured memory_bytes: 9132
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define i_i pair<int, int>
#define MAX_N 710

using namespace std;

vector<vector<bool>> g(MAX_N, vector<bool>(MAX_N));
vector<int> visited(MAX_N, -1);
int N;

void dfs(int *num, int i) {
    for (int j = 1; j <= N; j++) {
        if (!g[i][j] && visited[j] == -1) {
            visited[j] = !visited[i];
            num[visited[j]] += 1;
            dfs(num, j);
        }
    }
}

int main() {
    int M;
    cin >> N >> M;
    int s, d;
    for (int i = 0; i < M; i++) {
        cin >> s >> d;
        g[s][d] = true, g[d][s] = true;
    }

    vector<i_i> c_g;
    int num[2];
    for (int i = 1; i <= N; i++) {
        if (visited[i] == -1) {
            num[0] = 1, num[1] = 0;
            visited[i] = 0;
            dfs(num, i);
            c_g.push_back({num[0], num[1]});
        }
    }

    for (int i = 1; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
            if (!g[i][j] && visited[i] == visited[j]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }

    vector<vector<int>> dp(c_g.size() + 1, vector<int>(N + 1, 0));
    dp[0][0] = 1;
    for (int i = 0; i < c_g.size(); i++) {
        for (int j = 0; j <= N; j++) {
            if (dp[i][j] != 0) {
                if (j + c_g[i].first <= N) dp[i + 1][j + c_g[i].first] = 1;
                if (j + c_g[i].second <= N) dp[i + 1][j + c_g[i].second] = 1;
            }
        }
    }

    int ans = N * N;
    for (int i = 0; i <= N; i++) {
        if (dp[c_g.size()][i] == 1) {
            ans = min(ans, i * (i - 1) / 2 + (N - i) * (N - i - 1) / 2);
        }
    }
    cout << ans << endl;
    return 0;
}


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

for _ in range(K):
    flag = True
    for a in A:
        if a != N: flag = False
    if flag: break

    imos = [0] * (N+1)
    for i in range(N):
        l = max(i-A[i],0)
        r = min(i+A[i],N-1)
        imos[l] += 1
        imos[r+1] += -1
    
    for i in range(N):
        imos[i+1] += imos[i]
    
    A = imos[:N]

for a in A[:N]:
    print(a, end=" ")
print()



Measured memory_bytes: 168372
<?php
$query = trim(fgets(STDIN));
list($a,$b) = sscanf($query,"%d %d");
for($i=1; $i<=10000; $i++){
    if(((intval((float)$i * 0.08) == $a)&&(intval((float)$i * 0.1) == $b))){
        printf($i);
        exit;
    }
}
printf(-1);

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  ll X; cin>>X;
  ll dp[X+200] = {0};
  vector<ll> v = {100,101,102,103,104,105};
  dp[0] = 1;
  REP(i,X){
    if(dp[i]){ for(ll x:v){ dp[i+x]=1; if(i+x==X){break;}} }
  }
  cout << dp[X] <<"\n";
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

LL X;
int K;
LL R[100011];
int Q;
LL T[100011], A[100011];

void MAIN() {
    scanf("%lld%d", &X, &K);
    REP (i, K) scanf("%lld", R+i);
    R[K] = 2000000000;

    scanf("%d", &Q);
    REP (i, Q) scanf("%lld%lld", T+i, A+i);

    LL low = 0, high = X;
    LL low_value = 0, high_value = X;
    LL time = 0;
    LL add = 0;
    int pos = 0;
    REP (i, K+1) {
	while (pos < Q && T[pos] <= R[i]) {
	    LL a = A[pos], t = T[pos];
	    LL ans;
	    if (a <= low) {
		ans = low_value;
	    } else if (high <= a) {
		ans = high_value;
	    } else {
		ans = a + add;
	    }
	    amax(ans, 0LL);
	    amin(ans, X);

	    if (i % 2 == 0) {
		ans -= t - time;
	    } else {
		ans += t - time;
	    }
	    amax(ans, 0LL);
	    amin(ans, X);
	    printf("%lld\n", ans);
	    pos++;
	}

	LL diff = R[i] - time;
	if (i % 2 == 0) {
	    if (low_value < diff) {
		low += diff - low_value;
		low_value = 0;
	    } else {
		low_value -= diff;
	    }
	    high_value -= diff;
	    amax(high_value, 0LL);
	    add -= diff;
	} else {
	    if (high_value + diff > X) {
		high -= high_value + diff - X;
		high_value = X;
	    } else {
		high_value += diff;
	    }
	    low_value += diff;
	    amin(low_value, X);
	    add += diff;
	}

	time = R[i];
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



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

int mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int64_t N;
    cin >> N;
    map<int64_t, int64_t> hist;

    int64_t a = 2;
    while (N >= a * a)
    {
        if (N % a == 0)
        {
            hist[a]++;
            N /= a;
        }
        else
            a++;
    }


    hist[N]++;
    int ans = 0;
    for (auto p : hist)
    {
        int tmp = p.second;
        int x = 1;
        while (tmp >= x)
        {
            ans++;
            tmp -= x;
            x++;
        }
    }
    if (N != 1)
        cout << ans;
    else
        cout << 0;
}

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

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define lli long long int
#define ld long double
#define vec vector
#define forn(a) for(lli a=0; a<n; a++)
#define all(x) x.begin(), x.end()
#define deb(x) cerr<<#x<<" = "<<x<<endl

using namespace std;

int main(){
  IOS;

  int n; cin>>n;

  vec<int> v(n);
  forn(i) cin>>v[i];

  vec<int> c(n);
  forn(i) cin>>c[i];

  vec<int> info(n);
  forn(i) info[i] = v[i]-c[i];

  sort(all(info));
  reverse(all(info));

  int sum = 0;
  for(auto it: info){
    if(it<0) break;
    sum += it;
  }

  cout<<sum<<endl;

  return 0;
}

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

using namespace std;

typedef long long ll;

const ll MAXN = 21, MOD = 1e9 + 7;

int N, a[MAXN][MAXN];
vector<vector<ll>> dp;

ll pairs(int i, int mask) {
    if (i < 0)
        return 1;
    if (dp[i][mask] == -1) {
        dp[i][mask] = 0;
        for (int j = 0; j < N; j++)
            if (a[i][j] && (mask & (1 << j)))
                dp[i][mask] = (dp[i][mask] + pairs(i - 1, mask & ~(1 << j))) % MOD;
    }
    return dp[i][mask];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            cin >> a[i][j];
    dp.assign(N, vector<ll>(1 << N, -1));
    cout << pairs(N - 1, (1 << N) - 1) << endl;
}


Measured memory_bytes: 360832
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dl double long
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rrep(i, m, n) for(ll i = (ll)(m); i > (ll)(n); --i)
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;

struct node{
    int parent, right_sibling, left_child;
};

int getdepth(node *T, int id){
    int depth = 0;
    while(T[id].parent != -1){
        depth++;
        id = T[id].parent;
    }
    return depth;
}

string gettype(node *T, int id){
    if(T[id].parent == -1) return "root";
    else if(T[id].left_child == -1) return "leaf";
    else return "internal node";
}

vector<int> getchilds(node *T, int id){
    vector<int> childs;
    if(T[id].left_child == -1) return childs;
    childs.push_back(T[id].left_child);
    while(T[childs[childs.size()-1]].right_sibling != -1){
        childs.push_back(T[childs[childs.size()-1]].right_sibling);
    }
    return childs;
}

int main(void){
    int n;
    cin >> n;
    node *T = new node[n];
    rep(i, 0, n){
        T[i].parent = -1;
        T[i].right_sibling = -1;
        T[i].left_child = -1;
    }
    rep(i, 0, n){
        int id, k, v;
        cin >> id >> k;
        if(k != 0){
            cin >> v;
            T[id].left_child = v;
            T[v].parent = id;
            rep(j, 0, k-1){
                cin >> T[v].right_sibling;
                v = T[v].right_sibling;
                T[v].parent = id;
            }
        }
    }

    rep(i, 0, n){
        cout << "node " << i << ": parent = " << T[i].parent << ", depth = ";
        int depth = getdepth(T, i);
        cout << depth << ", " << gettype(T, i) << ", [";
        vector<int> c = getchilds(T, i);
        for(auto itr = c.begin(); itr != c.end(); ++itr){
            if(itr != c.begin()) cout << ", ";
            cout << *itr;
        }
        cout << ']' << endl;
    }

    return 0;
}


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


void solve(long long N){
    if (N <= 999) {
        cout << "ABC" << endl;
    }else{
        cout << "ABD" << endl;
    }
    
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

using namespace std;
int main()
{
 int element;
int vertex[5];
memset(vertex,0,sizeof(vertex));

for(int i=0;i<6;i++)
{
cin>>element;
vertex[element]++;
}
for(int i=1;i<=4;i++)
{
if(vertex[i]>2)
{
	
cout<<"NO";
return 0;
}

}
cout<<"YES";
return 0;
}


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

int main () {
  int A, B, C, K; 
  cin >> A >> B >> C >> K;
  
  int i = 0;
  int answer = 0;
  int flag = 0;
  
  for (; i < K && i < A; i++){
    answer++;
    if (i == K)
      flag++;
  }
  
  for (; i < K && i < A + B; i++){
    if (i == K)
      flag++;
  }
  
  for (; i < K && i < A + B + C; i++){
    answer--;
    if (i == K)
      flag++;
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 32;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

int w, h, sx, sy, cnt;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int maze[MAX][MAX];

bool range(int x, int y) {
    return (0 <= x && x < w && 0 <= y && y < h);
}

void dfs(int x, int y){
    maze[y][x] = 0;
    cnt++;
    rep(4, d) {
        if (range(x+dx[d], y+dy[d]) && maze[y+dy[d]][x+dx[d]]) {
            dfs(x+dx[d], y+dy[d]);
        }
    }
    return;
}

void solve(void){
    while (1) {
        cin >> w >> h;
        if (w == 0 && h == 0) break;
        cnt = 0;
        rep(h, y) rep(w, x) {
            char c; cin >> c;
            if (c == '#') maze[y][x] = 0;
            else maze[y][x] = 1;
            if (c == '@') {
                sx = x; sy = y;
            }
        }
        dfs(sx, sy);
        printf("%d\n", cnt);
    }
}

int main(void){
  solve();
  return 0;
}



Measured memory_bytes: 3220
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<stdio.h>
using namespace std;
typedef unsigned long long ll;
ll mod = (10e+8)+ 7;

int main(){
	int N;
	cin>>N;
	cout<<N / 2 - !(N % 2)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(x)				(x).begin(),(x).end()
#define REP(i, n)			for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)		for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF					(ll)1e9
#define EPS					(double)1e-9
#define MOD					(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)			(((((x))+((n)-1))/(n)))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)			(((((x))+((n)-1))/(n))*(n))	/* Nの倍数に切り上げ */
#define FloorN(x, n)		((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)			(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)			(!IsOdd((x)))						
#define M_PI				3.14159265358979323846
typedef long long			ll;
typedef pair<ll, ll>		P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
// メイン
int main()
{
	int N;
	cin >> N;
	vector<int> P(N);
	REP(i, N) cin >> P[i];

	int ans = 0;
	int minVal = INF;
	REP(i, N) {
		if (P[i] < minVal) {
			ans++;
			minVal = P[i];
		}
	}

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



Measured memory_bytes: 1024
N, K = map(int, input().split())
x = list(map(int, input().split()))
ans = float('inf')
for i in range(N - K + 1):
    L = x[i]
    R = x[i + K - 1]
    if R < 0:
        ans = min(ans, -L)
    elif L < 0 <= R:
        ans = min(ans, -2 * L + R, -L + 2 * R)
    else:
        ans = min(ans, R)

print(ans)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,d;
  cin >> n >> d;
  int ans = 0;
  vector<vector<int>> v(n,vector<int>(d));
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin >> v[i][j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=n-1;i<j;j--){
      int sum = 0;
       for(int k=0;k<d;k++){
         sum += (v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
       }
       double x = sqrt(sum);
      if(x == floor(x)){
             ans++;
         }
    }
  }
  cout << ans << endl;
}
      


Measured memory_bytes: 256
import scala.io.StdIn.{readInt,readLine}

object Main {
  def calc(n:Int):Int = {
    val op = readLine
    op match {
      case "+" => calc(n+readInt)
      case "-" => calc(n-readInt)
      case "*" => calc(n*readInt)
      case "/" => calc(n/readInt)
      case _ => n
    }
  }

  def main(args:Array[String]) = println(calc(readInt))
}

Measured memory_bytes: 43516
//
// Created on 2020/09/10.
//

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    int n;
    cin>>n;
    priority_queue<int>p_q;
    for (int i = 0; i < n; ++i) {
        int a;
        cin>>a;
        p_q.push(a);
    }
    int alice = 0;
    int bob = 0;
    int turn = true;
    while(!p_q.empty()){
        int card = p_q.top();
        p_q.pop();
        if(turn)alice += card;
        else bob += card;
        turn = !turn;
    }

    cout<<alice-bob<<endl;

    return 0;
}



Measured memory_bytes: 3588
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

string S;

int main() {

	cin >> S;

	if (S == "RRR")
		cout << 3 << endl;
	else if (S == "RRS" || S == "SRR")
		cout << 2 << endl;
	else if (S == "SSS")
		cout << 0 << endl;
	else
		cout << 1 << endl;

	return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>

int main(void){

   int a,b,c,d;

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

   if(c<b){
      d=b;
      b=c;
      c=d;
   }

   if(b<a){
      d=a;
      a=b;
      b=d;
   }

   if(c<b){
      d=b;
      b=c;
      c=d;
   }
   
   printf("%d %d %d\n",a,b,c);
   return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
int main(){
  set<int> a;
  int s; cin >> s;
  a.insert(s);
  vector<int> suuretu;
  suuretu.push_back(s);
  while(1){
    if(s % 2 == 0) s /=2;
    else		   s = 3 * s + 1;
    if(a.count(s)){
      suuretu.push_back(s);
      break;
    }
    a.insert(s);
    suuretu.push_back(s);
  }
  cout << suuretu.size();
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
ll A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z;
void Otoshidama() {
	cin >> N >> Y;
	
	for (size_t i = 0; i <= N; i++)
	{
		for (size_t j = i; j <= N; j++)
		{
			for (size_t k = j; k <= N; k++)
			{
				ll a = j;
				ll b = k - j;
				ll c = N - k;
				if (a * 10000LL + b * 5000LL + c * 1000LL == Y) {
					cout << a << " " << b << " " << c << endl;
					return;
				}
			}
		}
	}
	cout << "-1 -1 -1" << endl;
}
int main() {
	Otoshidama();
	return 0;
}

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

int main() {
  int n,d;
  cin >> n >> d;
  if (n%(2*d+1)==0){
    cout << n/(2*d+1) << endl;
  }
  else{
    cout << n/(2*d+1)+1 << endl;
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

class Dict:
  def __init__(self, size):
    self.table = [None] * 1046527
    self.table_size = 1046527

  def insert(self, val):
    key = self.get_key(val)
    collision = 0
    while True:
      h = self.generate_hash(key, collision)
      if self.table[h] is None:
        self.table[h] = val
        break
      elif self.table[h] == val:
        break
      collision += 1
  def find(self, val):
    key = self.get_key(val)
    collision = 0
    while True:
      h = self.generate_hash(key, collision)
      if self.table[h] == val: return 1
      elif self.table[h] is None: return 0
      collision += 1

  def get_key(self, val):
    sum, P = 0, 1
    for i in range(len(val)):
      sum += P * self.get_char(val[i])
      P *= 5
    return sum

  def get_char(self, ch):
    if ch == 'A': return 1
    elif ch =='C': return 2
    elif ch =='G': return 3
    elif ch =='T': return 4
    else: return 0

  def generate_hash(self, key, collision):
    h1 = key % self.table_size
    h2 = 1 + key % (self.table_size - 1)
    return (h1 + collision * h2) % self.table_size

def _main():
  N = int(input())
  d = Dict(N)
  commands = [input().split() for _ in range(N)]

  for i in range(N):
    if commands[i][0] == 'insert':
      d.insert(commands[i][1])
    else:
      ans = 'yes' if d.find(commands[i][1]) else 'no'
      print(ans)



if __name__ == '__main__':
  _main()


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

int main(){
	string a,b,c;
	cin>>a>>b>>c;
	int d='A'-'a';
	a[0]+=d;
	b[0]+=d;
	c[0]+=d;
	cout<<a[0]<<b[0]<<c[0]<<endl;
	return 0;
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int abc=0;
  for (int i=0;i<n-2;i++){
    if(s.at(i)=='A'&&
        s.at(i+1)=='B'&&
        s.at(i+2)=='C'
        )
      abc++;
  }
  cout << abc << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n,k=MI()
    aa=LI()
    cs=[0]*(n+1)
    s=0
    for i,a in enumerate(aa,1):
        cs[i]=(cs[i-1]+a-1)%k
    #print(cs)
    cnt=defaultdict(int)
    ans=0
    for i,c in enumerate(cs):
        if i-k>=0:cnt[cs[i-k]]-=1
        ans+=cnt[c]
        cnt[c]+=1
    print(ans)

main()

Measured memory_bytes: 40840
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		BigDecimal n = stdIn.nextBigDecimal();
		BigDecimal m = stdIn.nextBigDecimal();



		System.out.println(n.multiply(m).setScale(0, BigDecimal.ROUND_DOWN));

		stdIn.close();
	}
}


Measured memory_bytes: 37488
/*
 * main.c
 *
 *  Created on: 2019/12/29
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;

int P[200002] = {0};
int main()
{
	int N = 0, i = 1, ans = 0, j = 1, min = 0;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &P[i]);
	}
	min = P[1];
	for (j = 1; j <= N; j++) {
		if (P[j] > min) {
			//
		} else {
			ans++;
		}
		min = MIN(min,P[j]);
	}
	printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 896
import math
X,K,D = [int(v) for v in input().split()]

if K * D < abs(X):
    if X < 0:
        print(abs(X + (K*D)))
    else:
        print(abs(X - (K*D)))
else:
    tmp = abs(X) // D
    K -= tmp
    if X < 0:
        X += tmp * D
    else:
        X -= tmp * D

    if K % 2== 1:
        if X > 0:
            print(abs(X-D))
        else:
            print(abs(X+D))
    else:
        print(abs(X))



Measured memory_bytes: 9172
#include <algorithm>
#include <cstdio>
#define MOD 1000000007
int arr[105], dp[105][105][105];
int main()
{
	// freopen("AGC012-F.in", "r", stdin);
	int n;
	scanf("%d", &n);
	int len = n * 2 - 1;
	for (int i = 0; i < len; i++)
		scanf("%d", arr + i);
	std::sort(arr, arr + len);
	dp[n - 1][0][0] = 1;
	for (int i = n - 1; i; i--)
	{
		bool l = arr[i] != arr[i - 1], r = arr[len - i - 1] != arr[len - i];
		for (int j = 0; j <= len; j++)
		{
			for (int k = 0; k <= len; k++)
			{
				if (!dp[i][j][k])
					continue;
				(dp[i - 1][j + l][k + r] += dp[i][j][k]) %= MOD;
				for (int x = 0; x < j + l; x++)
					(dp[i - 1][x][k + r + 1] += dp[i][j][k]) %= MOD;
				for (int x = 0; x < k + r; x++)
					(dp[i - 1][j + l + 1][x] += dp[i][j][k]) %= MOD;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i <= len; i++)
	{
		for (int j = 0; j <= len; j++)
			(ans += dp[0][i][j]) %= MOD;
	}
	printf("%d\n", ans);
	return 0;
}


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

#define MAX_W 100
#define MAX_H 100
char farm[MAX_W][MAX_H];
int W, H;
const int direction[4][2] = {
    { -1, 0 },
    { 1, 0 },
    { 0, -1 },
    { 0, 1 },
};

void dfs(const int& x, const int& y, const char tree)
{
    farm[x][y] = 'x';
    for (int i = 0; i < 4; ++i)
    {
        int nx = x + direction[i][0];
        int ny = y + direction[i][1];
        if (nx >= 0 && nx < W && ny >= 0 && ny < H && farm[nx][ny] == tree)
        {
            dfs(nx, ny, tree);
        }
    }
}

///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
    
    while (cin >> H >> W, W > 0)
    {
        int res = 0;
        int x, y;
        for (y = 0; y < H; ++y)
        {
            for (x = 0; x < W; ++x)
            {
                cin >> farm[x][y];
            }
        }
        
        for (y = 0; y < H; ++y)
        {
            for (x = 0; x < W; ++x)
            {
                if (farm[x][y] != 'x')
                {
                    dfs(x, y, farm[x][y]);
                    ++res;
                }
            }
        }
        cout << res << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1788
void main() {
	auto X = ri, A = ri, B = ri;
	X -= A;
	(X % B).writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


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

using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> hist(N + 1, 0);
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    hist[A]++;
  }

  sort(hist.begin(), hist.end());
  int ans = 0;
  for (int i = 0; N - i >= K; i++) {
    ans += hist[i];
  }
  cout << ans << endl;

  return 0;
}


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

    namespace b
    {
        class Program
        {
            static void Main(string[] args)
            {
                var _ = Console.ReadLine().Split();
                var a = int.Parse(_[0]);
                var b = int.Parse(_[1]);

                var count = 0;
                var socket = 1;

                while(b > socket){
                    socket += a - 1;
                    count++;
                }

                Console.WriteLine(count);
            }
        }
    }


Measured memory_bytes: 13140
using System;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            string[] read = new string[4];
            read = Console.ReadLine().Split(' ');
            int A = int.Parse(read[0]);
            int B = int.Parse(read[1]);
            int C = int.Parse(read[2]);
            int D = int.Parse(read[3]);
            int S1 = A * B;
            int S2 = C * D;
            if(S1 >= S2){
                Console.WriteLine(S1);
            }else{
                Console.WriteLine(S2);
            }

            //var c1 = new MyClass();
            //Console.WriteLine($"Hello World! {c1.ReturnMessage()}");
        }
    }
}

Measured memory_bytes: 13140
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 4
#define L 46

int result[N][N] = {
  {1,2,3,4},
  {5,6,7,8},
  {9,10,11,12},
  {13,14,15,0}};

int x[N*N] = {3,0,1,2,
	      3,0,1,2,
	      3,0,1,2,
	      3,0,1,2};
int y[N*N] = {3,0,0,0,
	      0,1,1,1,
	      1,2,2,2,
	      2,3,3,3};

int min = L;


void dfs(int p1[N][N], int p2[N][N],int n){
  int i,j,i1,j1;
  int f = 0, d = 0;
  int tmp[N][N];

  for(i = 0; i<N ; i++){
    for(j = 0; j<N; j++){
      if(result[i][j] != p1[i][j]){
	f++;
      }
      if(p1[i][j] == 0){
	i1 = i;
	j1 = j;
      }
      else {
	d += abs(j - x[p1[i][j]]) + abs(i -y[p1[i][j]]);
      }
    }
  }
  if(f == 0){
    if(min > n){
      min = n;
    }
    return;
  }
  if(d + n> min){
    return;
  }
  if( i1>0&& i1<N){
    memcpy(tmp,p1,sizeof(int) * N *N);
    f = tmp[i1][j1];
    tmp[i1][j1] = tmp[i1-1][j1];
    tmp[i1-1][j1] = f;
    if(memcmp( tmp,p2,sizeof(int)*N*N) != 0){
      dfs(tmp,p1,n+1);
    }
  }

  if( j1>0&& j1<N){
    memcpy(tmp,p1,sizeof(int) * N *N);
    f = tmp[i1][j1];
    tmp[i1][j1] = tmp[i1][j1-1];
    tmp[i1][j1-1] = f;
    if(memcmp( tmp,p2,sizeof(int)*N*N) != 0){
      dfs(tmp,p1,n+1);
    }
  }


 if( i1>=0&& i1<N-1){
    memcpy(tmp,p1,sizeof(int) * N *N);
    f = tmp[i1][j1];
    tmp[i1][j1] = tmp[i1+1][j1];
    tmp[i1+1][j1] = f;
    if(memcmp( tmp,p2,sizeof(int)*N*N) != 0){
      dfs(tmp,p1,n+1);
    }
 }

 if( j1>=0&& j1<N-1){
    memcpy(tmp,p1,sizeof(int) * N *N);
    f = tmp[i1][j1];
    tmp[i1][j1] = tmp[i1][j1+1];
    tmp[i1][j1+1] = f;
    if(memcmp( tmp,p2,sizeof(int)*N*N) != 0){
      dfs(tmp,p1,n+1);
    }
 }
}


int main(){
  int i,j;
  int p[N][N];
  for(i = 0;i<N; i++){
    for(j = 0;j<N;j++){
      scanf("%d",&p[i][j]);
    }
  }
  dfs(p,p,0);
  printf("%d\n",min);
  return 0;
}



Measured memory_bytes: 2092
import java.util.Scanner;

public class Main {

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

		if(Math.abs(a-b)%2==0) {
			System.out.println((a>b)? Math.abs(a-Math.abs(a-b)/2) : Math.abs(a+Math.abs(a-b)/2));
		}else {
			System.out.println("IMPOSSIBLE");
		}

	}
}


Measured memory_bytes: 23380
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)

  val m1 = sc.nextInt
  val d1 = sc.nextInt
  val m2 = sc.nextInt
  val d2 = sc.nextInt

  val res = if(m1 != m2) "1" else "0"

  println(res)
}

Measured memory_bytes: 25532
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main() {
  vector<unsigned long> a(5);
  vector<unsigned long> c(5);
  unsigned long n;
  cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

  c[0] = n;

  for(unsigned long i=0; i<5; i++) {
    c[i] = (unsigned long) ceil((double) n / a[i]);
  }
  
  unsigned long m = *max_element(c.begin(), c.end());
  m += 4;

  cout << m << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stack>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;

int main() {
	int s;
	cin >> s;
	int t;
	cin >> t;
	int ans = s + t;
	if (ans >= 24)ans -= 24;
	cout << ans << endl;
}

Measured memory_bytes: 256
import itertools

N=int(input())
xy=[list(map(int, input().split())) for _ in range(N)]
xy_d=[[0]*N for _ in range(N)]
xylist=list(itertools.permutations([n for n in range(N)],N))

for i in range(N-1):
	for h in range(i+1,N):
		xy_d[i][h]=((xy[i][0]-xy[h][0])**2+(xy[i][1]-xy[h][1])**2)**.5
		xy_d[h][i]=((xy[i][0]-xy[h][0])**2+(xy[i][1]-xy[h][1])**2)**.5

ans=0

#print(xy_d)

for g in range(len(xylist)):
	for t in range(N-1):
		#print(xy_d[xylist[g][t]][xylist[g][t+1]])
		ans+=xy_d[xylist[g][t]][xylist[g][t+1]]

print(ans/len(xylist))

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll N,M,S;

vector<ll> dir[100],dist[100],cost[100];

ll C[100],D[100];

ll d[200005];
ll ans[100];

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

    cin >> N >> M >> S;

    ll u,v,a,b;

    for (int i = 0;i < M;i++){
        cin >> u >> v >> a >> b;
        u--;
        v--;
        dir[u].push_back(v);
        dir[v].push_back(u);
        dist[u].push_back(b);
        dist[v].push_back(b);
        cost[u].push_back(a);
        cost[v].push_back(a);
    }

    for (int i = 0;i < N;i++){
        cin >> C[i] >> D[i];
    }

    for (int i = 0;i < 200005;i++){
        d[i] = LLONG_MAX;
    }

    for (int i = 0;i < N;i++){
        ans[i] = LLONG_MAX;
    }

    S = min(S,2999LL);

    d[S] = 0;
    priority_queue<P,vector<P>,greater<P>> que;
    que.push(P(0,S));

    while(que.size()){
        P p = que.top(); que.pop();
        ll now = p.second, sum = p.first;
        ll node = now/3000, sil = now%3000;
        if(d[now] < sum) continue;
        if(sil < 2600){
            ll nex_sil = min(sil+C[node],2999LL);
            ll nex = node*3000+nex_sil;
            if(d[nex] > sum+D[node]){
                d[nex] = sum+D[node];
                que.push(P(sum+D[node],nex));
            }
        }
        for (int i = 0;i < dir[node].size();i++){
            if(sil < cost[node][i]) continue;
            ll time = dist[node][i];
            ll to   = dir[node][i];
            ll nex_sil = sil - cost[node][i];
            ll nex = to*3000+nex_sil;
            if(d[nex] > sum+time){
                d[nex] = sum+time;
                ans[to] = min(ans[to],d[nex]);
                que.push(P(sum+time,nex));
            }
        }
    }

    for (int i = 1;i < N;i++){
        cout << ans[i] << endl;
    }

    return 0;

}

Measured memory_bytes: 6916
(eval-when (:compile-toplevel)
  #-swank (proclaim '(optimize (speed 3) (debug 0) (safety 0))))

(defparameter inf 2000000000)

(defun read-integer (&optional (in *standard-input*))
  (declare (inline read-byte))
  (labels ((number-char-p (b)
             (<= #.(char-code #\0) b #.(char-code #\9)))
           (minus-char-p (b)
             (= b #.(char-code #\-)))
           (to-number (b)
             (- b #.(char-code #\0))))
    (declare (inline number-char-p minus-char-p to-number))
    (macrolet ((%read-byte ()
                 '(the (unsigned-byte 8)
                       #+swank (char-code (read-char in nil #\Nul))
                       #-swank (read-byte in nil 0))))
      (let* ((minus-p nil)
             (x (loop for b = (%read-byte)
                      if (number-char-p b)
                        return (to-number b)
                        end
                      if (minus-char-p b)
                        do (setf minus-p t))))
        (declare (boolean minus-p) (fixnum x))
        (the fixnum (loop for b = (%read-byte)
                          and y = x then (+ (* y 10) (to-number b))
                          unless (number-char-p b)
                            return (funcall (if minus-p #'- #'+) y)))))))

(defun split (x str &optional (acc nil))
  (let ((pos (search x str))
        (size (length x)))
    (if pos
        (split x (subseq str (+ pos size)) (cons (subseq str 0 pos) acc))
        (nreverse (cons str acc)))))

(defmacro minf (field &rest x)
  `(setf ,field (min ,field ,@x)))

(defmacro maxf (field &rest x)
  `(setf ,field (max ,field ,@x)))

(defun solve (stairs n)
  (let ((dp (make-array n :element-type 'integer :initial-element inf)))
    (setf (aref dp 0) 0)
    (dotimes (i (1- n))
      (minf (aref dp (1+ i)) (+ (aref dp i) (abs (- (aref stairs i) (aref stairs (1+ i))))))
      (if (< (+ i 2) n)
          (minf (aref dp (+ i 2)) (+ (aref dp i) (abs (- (aref stairs i) (aref stairs (+ i 2))))))))
    (aref dp (1- n))))

(let* ((n (parse-integer (read-line)))
       (stairs (make-array n :adjustable t :fill-pointer 0)))
  (dotimes (i n)
    (vector-push (read-integer *standard-input*) stairs))
  (format t "~A~%" (solve stairs n)))



Measured memory_bytes: 26384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

ll binary_search(
    ll lo, ll hi, function<bool(ll)> is_ok,
    bool maximize
){
    while(lo < hi){
        if(maximize){
            const ll mid = (lo + hi + 1) / 2;
            if(is_ok(mid)){
                lo = mid;
            }else{
                hi = mid - 1;
            }
        }else{
            const ll mid = (lo + hi) / 2;
            if(is_ok(mid)){
                hi = mid;
            }else{
                lo = mid + 1;
            }
        }
    }
    return lo;
}


ll ask(vector<ll>& a){
    cout << "? ";
    REP(i, a.size()){
        cout << a.at(i) + 1;
        if(i + 1 < a.size()){
            cout << ' ';
        }
    }
    cout << endl << flush;
    string s;
    cin >> s;
    if(s == "Red"){
        return 0;
    }else if(s == "Blue"){
        return 1;
    }else{
        exit(0);
    }
}

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

    vector<ll> tmp(n);
    REP(i, n){ tmp.at(i) = i; }
    ll col0 = ask(tmp);

    ll pos = binary_search(
        1, n,
        [&](ll mid) -> bool {
            vector<ll> tmp(n);
            REP(i, n){ tmp.at(i) = mid + i; }
            ll col = ask(tmp);
            return col != col0;
        },
        false
    );

    vector<ll> ans(2 * n, -1);
    ans.at(pos - 1) = col0;
    ans.at(pos + n - 1) = 1 - col0;

    REP(i, 2 * n){
        if(ans.at(i) != -1){
            continue;
        }
        vector<ll> tmp(n);
        tmp.at(0) = i;
        if(i < pos || i >= pos + n){
            REP(j, n - 1){
                tmp.at(j + 1) = pos + j;
            }
        }else{
            REP(j, n - 1){
                tmp.at(j + 1) = (pos + n + j) % (2 * n);
            }
        }
        ans.at(i) = ask(tmp);
    }

    cout << "! ";
    REP(i, 2 * n){
        if(ans.at(i) == 0){
            cout << 'R';
        }else{
            cout << 'B';
        }
    }
    cout << endl << flush;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
	int a,b,c;
	cin >>a >> b >>c;
	(a <= c && c <= b)?Yes : No;
	return  0;
}

Measured memory_bytes: 256