akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

#define N_MAX   (100)

int main()
{
    // 整数の入力
    int N , s, e;
    int result = 0;
    cin >> N;
    int h[N_MAX];

    for (int i = 0; i <= N; i++) cin >> h[i];

    while (true) {
        for (int i = 0; i < N; i++) {
            s = -1; e = -1;
            if (h[i] != 0 ) {
                s = i;
                for (int j = s; j >= s; j++) {
                    if (h[j] == 0) {
                        e = j-1;
                        break;
                    }
                    if (j == N - 1) e = N - 1;
                }
                break;
            }
        }

        if (s == -1) {
            break;
        }

        result++;
        for (int i = s; i <= e; i++) {
            h[i]--;
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    int s = (A+B+C)/2;
    int S = sqrt(s*(s-A)*(s-B)*(s-C));
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line)
});

reader.on('close', () => {

  var s = {}
  var w = lines[0].split('')

  for (var val of w) {
    s[val] = 0
  }

  for (var val of w) {
    s[val] += 1
  }

  var r = 'Yes'

  for (var val of w) {
    if (s[val] !== 2) {
      r = 'No'
    }
  }

  console.log(r)

});

Measured memory_bytes: 7500
// AGC020
// B - Ice Rink Game

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

int K;
vector<int> a;

int main() {
    cin >> K;
    a.resize(K);
    for (int i = 0; i < K; i++) {
        cin >> a[i];
    }

    ll l = 2, r = 2;
    for (int i = K - 1; i >= 0; i--) {
        l = (l + a[i] - 1) / a[i] * a[i];
        r = r / a[i] * a[i] + a[i] - 1;
        if (l > r) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << l << " " << r << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>

template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

template <class T>
struct Combination {
    int max_n;
    std::vector<T> f, invf;

    explicit Combination(int n)
        : max_n(n), f(n + 1), invf(n + 1) {
        f[0] = 1;
        for (int i = 1; i <= n; ++i) {
            f[i] = f[i - 1] * i;
        }

        invf[max_n] = f[max_n].inv();
        for (int i = max_n - 1; i >= 0; --i) {
            invf[i] = invf[i + 1] * (i + 1);
        }
    }

    T fact(int n) const { return f[n]; }
    T invfact(int n) const { return invf[n]; }
    T perm(int a, int b) const {
        return a < b || b < 0 ? T(0) : f[a] * invf[a - b];
    }
    T comb(int a, int b) const {
        return a == b ? 1 : a < b || b < 0 ? T(0) : f[a] * invf[a - b] * invf[b];
    }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

Combination<mint> C(4000000);

bool solve() {
    int a, b, c, x, y;
    std::cin >> a >> b >> c >> x >> y;

    int s = a + b + c;
    if (s == 0) return false;

    mint ans = 0;
    for (int l = 0; l <= x; ++l) {
        int d = x - l;
        int r = y - d;
        auto pat = C.comb(l - 1, a - 1) * C.comb(r - 1, b - 1) *
                   C.comb(d + s - 1, d);

        ans += pat;
    }

    ans *= C.comb(s, a) * C.comb(s - a, b);

    std::cout << ans << std::endl;
    return true;
}

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

    while (solve()) {}

    return 0;
}



Measured memory_bytes: 33748
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { -1, 0, 1,0 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////


int main() {
	int n, d; cin >> n >> d;
	int x[11][11];
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < d; ++j) {
			cin >> x[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < n - 1; ++i) {
		for (int j = i + 1; j < n; ++j) {
			int key = 0;
			for (int k = 0; k < d; ++k) {
				key += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
			}
			for (int i = sqrt(key); i <= sqrt(key); ++i) {
				if (i*i == key) {
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()

def check(s):
  if s[0] != 'A':
    print('WA')
    return
  
  if s[2:-1].count('C') != 1:
    print('WA')
    return
  
  s = s.strip('A')
  s = list(s)
  s.remove('C')
  s = ''.join(s)
  
  if s.islower() != True:
    print('WA')
    return
  
  print('AC')

check(s)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define F first
#define S second
const long long MOD ((long long)(1e9+7));
const long long N ((long long)(1e18));
using namespace std;
long long dp[100005];
int n,w,cost,ww,ans;
int main()
{

   scanf("%d %d",&n,&w);
   for(int i=0;i<100005;i++)
   {
      dp[i]=N;
   }
   dp[0]=0;
   for(int i=1;i<=n;i++)
   {
      scanf("%d %d",&ww,&cost);
      for(int j=100004;j>=0;j--)
      {
         if(dp[j]!=N)
         {
            dp[j+cost]=min(dp[j+cost],dp[j]+ww);
         }
      }
   }
   for(int i=0;i<=100004;i++)
   {
      if(dp[i]<=w)ans=i;
   }
   printf("%d",ans);
}


Measured memory_bytes: 1152
#include <stdio.h>
   #include <stdlib.h>
   #include <time.h>
    
   int main(){
   int e=0;
   int s=0;
   scanf("%d %d",&e,&s);
   if((e<=8)&&(s<=8))
   {
   	printf("Yay!\n");
   }
   else 
   {
   	printf(":(\n");
   }
       return 0;
   }

Measured memory_bytes: 128
from heapq import heappop,heappush
inf = float("inf")

n,m,s = map(int,input().split())

G = [[] for _ in range(n)]
for _ in range(m):
    u,v,cost,time = map(int,input().split())
    u -= 1
    v -= 1
    G[u].append((v,cost,time))
    G[v].append((u,cost,time))

for i in range(n):
    cost,time = map(int,input().split())
    G[i].append((i,-cost,time))

# mint[i][j]
# 銀貨j枚を持って都市iに着くことができる最小時間
mint = [[inf]*2451 for _ in range(n)]

# color[i][j]
# 銀貨j枚を持って都市iに着くことができる最小時間が確定したか
white = 0
black = 1
color = [[white]*2451 for _ in range(n)]

def dijkstra(u,s):
    # 銀貨50枚で49回移動が最大コスト、いらない分は捨てる
    s = min(s,2450)
    mint[u][s] = 0
    color[u][s] = black

    PQ = []
    heappush(PQ,(0,u,s))
    while PQ:
        # minv: PQ内の最小値
        # now: 今いる都市
        # nowcoins: 今持っている銀貨
        minv,now,nowcoins = heappop(PQ)
        color[now][nowcoins] = black
        
        # nxt: 次に行く都市
        # cost: 次の都市に行くのに使う銀貨
        # time: 次の都市に行くのにかかる時間
        # nxtcoins: 次の都市に行った段階で持っている銀貨
        for nxt,cost,time in G[now]:
            nxtcoins = min(nowcoins - cost,2450)
            if nxtcoins < 0: continue
            if color[nxt][nxtcoins]: continue
            if mint[nxt][nxtcoins] > minv + time:
                mint[nxt][nxtcoins] = minv + time
                heappush(PQ,(mint[nxt][nxtcoins],nxt,nxtcoins))

dijkstra(0,s)

# for i in range(n): print(mint[i])
# for i in range(n): print(color[i])
for i in range(1,n): print(min(mint[i]))

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

int main() {
  ios::sync_with_stdio(false);
  long N, K;
  cin >> N >> K;
  vector<long> A(N);
  for (long &a : A) cin >> a;
  sort(A.begin(), A.end());

  long L = -2e18, R = 2e18;
  while (R - L > 1) {
    long M = (L + R) / 2, cnt = 0;
    for (int i = 0; i < N; i++) {
      if (A.at(i) >= 0) {
        int l = i, r = N;
        while (r - l > 1) {
          int m = (l + r) / 2;
          (A.at(i) * A.at(m) <= M) ? l = m : r = m;
        }
        cnt += l - i;
      } else {
        int l = i, r = N;
        while (r - l > 1) {
          int m = (l + r) / 2;
          (A.at(i) * A.at(m) <= M) ? r = m : l = m;
        }
        cnt += N - r;
      }
    }
    (cnt < K) ? L = M : R = M;
  }
  cout << R << "\n";
}

Measured memory_bytes: 1792
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
int n;
pair<int,int>p[5005];
int dp[5005][5005];
bool cmp(pair<int,int>a,pair<int,int>b){
	return a.first+a.second<b.first+b.second;
}
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>p[i].first>>p[i].second;
	sort(p+1,p+n+1,cmp);
	memset(dp,inf,sizeof dp);
	dp[0][0]=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=n;j++){
			dp[i][j]=min(dp[i][j],dp[i-1][j]);
			if(j&&dp[i-1][j-1]<=p[i].first)
			dp[i][j]=min(dp[i][j],dp[i-1][j-1]+p[i].second);
		}
	}
	int ans=0;
	for(int i=0;i<=n;i++){
		if(dp[n][i]<=1e15){
			ans=max(ans,i);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 196096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9 + 7;
const int inf = 1e8;

int main() {
	int N;
	cin>>N;
	cout<<"Christmas";
	rep(i,25 - N){
	cout<<" "<<"Eve";
}
	cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
    #include <algorithm>
     
    struct edge
    {
    	int u, v, w;
    };
     
    struct point
    {
    	int firstCoordinate, secondCoordinate, position;
    };
     
    bool compare(const edge &x, const edge &y)
    {
    	return x.w < y.w;
    }
     
    bool compareByX(const point &x, const point &y)
    {
    	return x.firstCoordinate > y.firstCoordinate;
    }
     
    bool compareByY(const point &x, const point &y)
    {
    	return x.secondCoordinate > y.secondCoordinate;
    }
     
     
     
    int roots[200020], sums[200020], ans[200020] = { 0 }, maxSum = 0, position = 0;
     
    void initialize(int n)
    {
    	for (int i = 0; i < n; ++i)
    	{
    		roots[i] = i;
    		sums[i] = 1;
    	}
    }
     
    int root(int i)
    {
    	while (roots[i] != i)
    	{
    		roots[i] = roots[roots[i]];
    		i = roots[i];
    	}
    	
    	return i;
    }
     
    void makeUnion(edge edges[100010], int i)
    {
    	int rootOfA = root(edges[i].u), rootOfB = root(edges[i].v);
    	
    	if (sums[rootOfA] >= sums[rootOfB])
    	{
    		sums[rootOfA] += sums[rootOfB];
    		ans[rootOfA] += ans[rootOfB] + edges[i].w;
    		roots[rootOfB] = rootOfA;
    		
    		if (sums[rootOfA] > maxSum)
    		{
    			maxSum = sums[rootOfA];
    			position = i;
    		}
    	}
    	else
    	{
    		sums[rootOfB] += sums[rootOfA];
    		ans[rootOfB] += ans[rootOfA] + edges[i].w;
    		roots[rootOfA] = rootOfB;
    		
    		if (sums[rootOfB] > maxSum)
    		{
    			maxSum = sums[rootOfB];
    			position = i;
    		}
    	}
    }
     
    int main()
    {
    	int n, x, y;
    	std::cin >> n;
    	
    	edge edges[200020];
    	
    	point points[100010];
    	
    	for (int i = 0; i < n; ++i)
    	{
    		std::cin >> points[i].firstCoordinate >> points[i].secondCoordinate;
    		points[i].position = i;
    	}
    	
    	std::sort(points, points + n, compareByX);
    /*	for (int i = 0; i < n - 1; ++i)
    		std::cout << points[i].firstCoordinate << " " << points*/
    	for (int i = 0; i < n - 1; ++i)
    	{
    		edges[i].u = points[i + 1].position;
    		edges[i].v = points[i].position;
    		edges[i].w = points[i].firstCoordinate - points[i + 1].firstCoordinate;
    	}
    	
    	std::sort(points, points + n, compareByY);
    	for (int i = 0; i < n - 1; ++i)
    	{
    		edges[i + n - 1].u = points[i + 1].position;
    		edges[i + n - 1].v = points[i].position;
    		edges[i + n - 1].w = points[i].secondCoordinate - points[i + 1].secondCoordinate;
    	}
     
    	std::sort(edges, edges + (n + n) - 2, compare);
    	
    //	for (int i = 0; i < (n + n) - 2; ++i)
    //		std::cout << edges[i].u << " " << edges[i].v << " " << edges[i].w << "\n";
    	
    	initialize(n);
    	
    	for (int i = 0; i < (n + n) - 2; ++i)
    	{
    		if (root(edges[i].u) != root(edges[i].v))
    		{
    			makeUnion(edges, i);
    //			std::cout << edges[i].u << " " << edges[i].v << " " << edges[i].w << "\n"; 
    		}
    //		std::cout << edges[i].u << " " << edges[i].v << " " << edges[i].w << "\n";
    	}
     
    	std::cout << ans[root(position)];
    }

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

int main(){
    
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    if(n <= k){
        cout << x * n;
    }
    else{
        cout << x * k + (n - k) * y;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	char a[25];
	scanf("%s",a);
	a[5] = ' ';
	a[13] = ' ';
	for(int i = 0; i< 19; i++)
	printf("%c",a[i]);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        int result = 0;
        for (int i = 0; i < a.length; i++) {
            if (i == a[a[i] - 1] - 1) {
                result++;
            }
        }
        result /= 2;

        // 出力
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 49048
N,K = map(int,input().split())
V = list(map(int,input().split()))
import heapq
ans = -float('inf')
for i in range(min(N+1,K+1)):
    for j in range(min(N-i+1,K-i+1)):
        A = V[:i]
        B = V[N-j:]
        AB = A + B
        heapq.heapify(AB)
        k = 1
        c = 0
        s = 0
        while i+j+k<=K and len(AB)>0:
            c = heapq.heappop(AB)
            if  c >= 0:
                break
            k += 1
        s = sum(AB)
        if c >= 0:
            s += c
        ans = max(ans,s)
print(ans)

Measured memory_bytes: 50652
require 'set'

class Graph
	def initialize
		@nodes = Set.new
		@edges = Set.new
	end

	def add_node(label = nil)
		Node.new(label)
	end

	def add_edge(u, v)
		e = Edge.new(u, v)
		u.outgoings << e
		v.incomings << e
		e
	end
	
	def del_edge(e)
		u, v = e.from, e.to
		u.outgoings.delete(e)
		v.incomings.delete(e)
		e
	end

	class Node
		def initialize(label)
			@label = label
			@outgoings = Set.new
			@incomings = Set.new
		end
		
		def to_s
			@label
		end
		attr_accessor :incomings, :outgoings
		attr_reader :label
	end

	class Edge
		def initialize(u, v)
			@from = u	
			@to = v
		end
		attr_reader :from, :to
	end

	def reachable_from(s, reached = Set.new, root = true)
		reached << s	
		s.outgoings.each{|e|
			v = e.to
			next if reached.include?(v)
			reachable_from(v, reached, false) 
		}
		root ? reached : nil
	end
end

loop{
	n, m = gets.split.map(&:to_i)
	break if n == 0
	c = (1..m).map{ ['#'] + gets.chomp.split("") + ['#'] }
	tmp = ['#'] * (n + 2)
	c = [tmp] + c + [tmp]

	g = Graph.new
	nodes = (0..m+1).map{|y| (0..n+1).map{|x| g.add_node(c[y][x])}}	
	s = nil

	for y in 0..m+1
		for x in 0..n+1
			u = nodes[y][x]
			next if u.label == '#'
			s = u if u.label == '@'
			[[0,1], [0,-1], [1,0], [-1,0]].each{|dy, dx|
				v = nodes[y+dy][x+dx]
				g.add_edge(u, v) if v.label == '.'	
			}
		end
	end
	
	puts g.reachable_from(s).size
}

Measured memory_bytes: 8092
#include <vector>
#include <iostream>
              
static constexpr int kMax = 1000000;
              
int main() {  
  std::vector<int> tet, otet;
  int i = 1;  
  while (true) {
    int t = i * (i+1) * (i+2) / 6;
    if (t >= kMax) {
      break;  
    }         
    tet.push_back(t);
    if (t % 2 == 1) {
      otet.push_back(t);
    }         
    i += 1;   
  }           
  std::vector<int> dp(kMax, kMax);
  std::vector<int> odp(kMax, kMax);
  dp[0] = 0;  
  odp[0] = 0; 
              
  for (const int t : tet) {
    for (int i = t; i < kMax; i++) {
      dp[i] = std::min(dp[i], dp[i-t]+1);
    }         
  }           
  for (const int t : otet) {
    for (int i = t; i < kMax; i++) {
      odp[i] = std::min(odp[i], odp[i-t]+1);
    }         
  }           
              
  while (true) {
    int n;    
    std::cin >> n;
    if (n == 0) {
      break;  
    }         
    std::cout << dp[n] << " " << odp[n] << std::endl;
  }           
}             
  


Measured memory_bytes: 10496
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int a,b,c,t=0;
cin >> a >> b >> c;
t=a;
a=b;
b=t;
t=a;
a=c;
c=t;
 cout << a  << " " << b << " " << c;
return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pos = tuple<int, int, int>;
const int INF = INT_MAX / 2;

int main() {
  int H, W;
  cin >> H >> W;
  int x, y;
  cin >> y >> x;
  pos start = make_tuple(0, --x, --y);
  int goalx, goaly;
  cin >> goaly >> goalx;
  goalx--;
  goaly--;

  vector<vector<bool>> S(H, vector<bool>(W, false));
  vector<vector<int>> dis(H, vector<int>(W, INF));

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char c;
      cin >> c;
      if (c == '.') S[i][j] = true;
    }
  }

  priority_queue<pos, vector<pos>, greater<pos>> que;
  que.push(start);
  while (!que.empty()) {
    auto p = que.top();
    que.pop();
    const auto [d, x, y] = p;
    if (d >= dis[y][x]) continue;
    dis[y][x] = d;
    // A
    if (x - 1 >= 0 && S[y][x - 1] && dis[y][x - 1] > dis[y][x]) {
      que.push(make_tuple(d, x - 1, y));
    }
    if (x + 1 < W && S[y][x + 1] && dis[y][x + 1] > dis[y][x]) {
      que.push(make_tuple(d, x + 1, y));
    }
    if (y - 1 >= 0 && S[y - 1][x] && dis[y - 1][x] > dis[y][x]) {
      que.push(make_tuple(d, x, y - 1));
    }
    if (y + 1 < H && S[y + 1][x] && dis[y + 1][x] > dis[y][x]) {
      que.push(make_tuple(d, x, y + 1));
    }
    // B
    for (int i = y - 2; i < y - 2 + 5; i++) {
      for (int j = x - 2; j < x - 2 + 5; j++) {
        if (i < 0 || i >= H || j < 0 || j >= W || !S[i][j]) continue;
        if (dis[i][j] > d + 1) {
          que.push(make_tuple(d + 1, j, i));
        }
      }
    }
  }
  // for (int i = 0; i < H; i++) {
  //  for (int j = 0; j < W; j++) {
  //    cout << dis[i][j] << " ";
  //  }
  //  cout << endl;
  //}

  if (dis[goaly][goalx] == INF)
    cout << -1 << endl;
  else
    cout << dis[goaly][goalx] << endl;
}


Measured memory_bytes: 8980
#include<iostream>
#include<string.h>
using namespace std;
int main(void){
	char a[26]={'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'};
	char b[1000];
	int c[1000],i,n,s,kazu;
	cin>>b;
	for(i=0;i<1000;i++){
		c[i]=0;
	}
	kazu=strlen(b);
	n=0;
	for(i=0;i<kazu;i++){
		for(s=0;s<26;s++){
			if(b[i]==a[s]){
				if(s-3<0){
					c[n]=s+23;
					n++;
				}
				else{
					c[n]=s-3;
					n++;
				}
			}
		}
	}
	for(i=0;i<kazu;i++){
		cout<<a[c[i]];
	}
	cout<<endl;
	return 0;
}

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

int main()
{
    ll n,m,x,t;
    ll i,j,k;
    ll res=0;
    ll a[300007],b[300007];
    cin>>n;
    for(i=0;i<n;i++)cin>>a[i];
    b[0]=a[0];
    for(i=1;i<n;i++){
        b[i]=max(b[i-1],a[i]);
    }
    for(i=0;i<n;i++){
        res+=b[i]-a[i];
    }
    cout<<res;
}

Measured memory_bytes: 6692
def swap(dice,i,j,k,l):#diceの目をi→ｊ→ｋ→ｌ→iの順に入れ替える
    x=dice[l]
    dice[l]=dice[k]
    dice[k]=dice[j]
    dice[j]=dice[i]
    dice[i]=x
    return dice

def Sroll(dice):
    dice=swap(dice,0,1,5,4)
    return dice

def Eroll(dice):
    dice=swap(dice,0,2,5,3)
    return dice

def Wroll(dice):
    dice=swap(dice,0,3,5,2)
    return dice

def Nroll(dice):
    dice=swap(dice,0,4,5,1)
    return dice




dice1=list(map(int,input().split()))
dice2=list(map(int,input().split()))

top=dice1[0]
fro=dice1[1]

for j in range(0,8):
    if(fro==dice2[1]):
        break
    if(j==3):
        dice2=Eroll(dice2)
    dice2=Sroll(dice2)
while(top!=dice2[0]):
    dice2=Eroll(dice2)

if(dice1[2]==dice2[2]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5608
#include <iostream>
using namespace std;
void swap(int& a, int& b)
{
    int c=a;
     a=b;
     b=c;

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


Measured memory_bytes: 3044
#include <bits/stdc++.h>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

void BubbleSort(pair<int, char> x[], int n) {
    int minj , cnt = 0;
    pair<int, char> tmp;
    int flag = 1;
    while(flag) {
        flag = 0;
        for(int i = n-1; i > 0; i--) {
            if(x[i-1].first > x[i].first) {
                tmp = x[i];
                x[i] = x[i-1];
                x[i-1] = tmp;
                flag = 1;
            }
        }
    }
    rep(i, n) cout << x[i].second << x[i].first << ((i == n-1) ? "\n" : " ");
}

void SelectionSort(pair<int, char> x[], int n) {
    int minj , cnt = 0;
    pair<int, char> tmp;
    for(int i = 0; i < n; i++) {
        minj = i;
        for(int j = i; j < n; j++) {
            if(x[minj].first > x[j].first) {
                minj = j;
            }
        }
        if(minj != i)
        {
            tmp = x[i];
            x[i] = x[minj];
            x[minj] = tmp;
            cnt++;
        }
    }
    
    rep(i, n) cout << x[i].second << x[i].first << ((i == n-1) ? "\n" : " ");
}

int main() {
    int n;
    cin >> n;
    
    pair<int, char> bubble[n], selection[n];
    
    string in;
    rep(i, n) {
        cin >> in;
        bubble[i] = make_pair(in[1] - '0', in[0]);
        selection[i] = make_pair(in[1] - '0', in[0]);
    }
    
    BubbleSort(bubble,n);
    cout << "Stable" << endl;

    SelectionSort(selection,n);
    
    int flag = 1;
    rep(i,n) {
        char mark1 = bubble[i].second;
        char mark2 = selection[i].second;
        
        if(mark1 != mark2) {
            cout << "Not stable" << endl;
            return 0;
        }
        
    }
    cout << "Stable" << endl;
    
}
    



Measured memory_bytes: 3168
S=input().strip()
n=len(S)

def dfs(i):
    global st,S,ans
    if i==n-1:
        st=S
        c=0
        off=0
        for j in lis:
            c+=1
            if j==1:
                S=S[:c+off]+'+'+S[c+off:]
                off+=1
        #print(S)
        tm=S.split('+')
        for j in range(len(tm)):
            #print(tm[j])
            ans+=int(tm[j])

        S=st
        return
    lis.append(0)
    dfs(i+1)
    lis.pop(-1)
    lis.append(1)
    dfs(i+1)
    lis.pop(-1)
lis=[]
ans=0
dfs(0)
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

#define NO_DATA -1

int main(int argc, const char * argv[]) {
    // insert code here...
    int result[3];
    
    for (int i = 0; i < 3; i++ ) {
        result[i] = NO_DATA;
    }
    
    for (int i=0;i<10;i++){
        int data;
        scanf("%d",&data);
        if (result[0]<data) {
            result[2]=result[1];
            result[1]=result[0];
            result[0]=data;
        }
        else if (result[1]<data) {
            result[2]=result[1];
            result[1]=data;
        }
        else if (result[2]<data) {
            result[2]=data;
        }
    }
    
    for (int i = 0; i < 3; i++) {
        printf("%d\n",result[i]);
    }
    
    return 0;
}


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

int main() {
  
  int A=0, B=0, C=0;
  
  cin >> A >> B >> C;
  
  int music = B/A;
  
  if(music<C) {
    
    cout << music << endl;
    
  } else if(C<=music) {
    
    cout << C << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while (true) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            int r = sc.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = i + 1;
            }
            long[] kaijos = new long[n];
            kaijos[0] = 1;
            kaijos[1] = 1;
            for (int i = 2; i < n; i++) {
                kaijos[i] = (i * kaijos[i - 1]) % MOD;
            }
            for (int i = 0; i < r; i++) {
                int s = sc.nextInt() - 1;
                int t = sc.nextInt() - 1;
                int tmp = arr[s];
                arr[s] = arr[t];
                arr[t] = tmp;
            }
            long total = 0;
            ArrayList<Integer> used = new ArrayList<>();
            used.add(0);
            used.add(Integer.MAX_VALUE);
            for (int i = 0; i < n; i++) {
                int x = arr[i];
                int left = 0;
                int right = used.size() - 1;
                while (right - left > 1) {
                    int m = (left + right) / 2;
                    if (used.get(m) < x) {
                        left = m;
                    } else {
                        right = m;
                    }
                }
                used.add(right, x);
                total += (kaijos[n - i - 1] * (x - right)) % MOD;
                total %= MOD;
            }
            sb.append(total).append("\n");
        }
        System.out.print(sb);
    }
}



Measured memory_bytes: 160132
//コンテスト外
//saw

#include <bits/stdc++.h>
using namespace std;

int N,D,X,i ;
int A[100];
int main(){

  scanf("%d", &N);
  scanf("%d%d", &D, &X);
  for(int i=0;i<N;++i){
    scanf("%d", A + i);
  }
  int ans=X;
  for(int i=0; i<N;++i){
      int tmp = (D-1)/A[i]+1;
      ans += tmp;
  }
  cout <<ans<<endl ;
  return 0 ;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int N = Integer.parseInt(sc.next());
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());

        int sum = 0;
        for (int i = 1; i < N + 1; i++) {
            String[] val = String.valueOf(i).split("");

            int tmp = 0;
            for (String c : val) {
                tmp += Integer.parseInt(c);
            }

            if (A <= tmp && tmp <= B) {
                sum += i;
            }
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 32212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll N;
  cin>>N;
  
  vector<ll>A(N);
  vector<ll>ans(N);
  ll solve=INF;
  ll sum=0;
  rep(i,N){
    cin>>A[i];
    sum+=A[i];
    ans[i]=sum;
          }
  rep(i,N){
ll R=ans[i];
    ll L=sum-ans[i];
    
    ll av=(R+L)/2;
    ll num=abs(av-R)+abs(av-L);
  
  solve=min(solve,num);
  }

  cout<<solve<<endl;
}



Measured memory_bytes: 3328