akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    bool flag = false;
    rep(i, n) {
        ll a;
        cin >> a;
        if(a%2 == 1) {
            flag = true;
        }
    }

    if(flag) {
        out("first");
    }
    else {
        out("second");
    }
    
    re0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>


#define EPSILON 1e-9


class vector_t {
public:
  double x;
  double y;
  double z;

public:
  vector_t(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {};

public:
  double operator*(const vector_t& v) const {
    return x * v.x + y * v.y + z * v.z;
  };

  vector_t operator^(const vector_t& v) const {
    return vector_t(y * v.z - z * v.y,
                    z * v.x - x * v.z,
                    x * v.y - y * v.x);
  };

public:
  double length() const {
    return sqrt(*this * *this);
  };
};


class point_t {
public:
  double x;
  double y;
  double z;
  double w;

public:
  point_t(double x = 0, double y = 0, double z = 0, double w = 1) : x(x), y(y), z(z), w(w) {};
  
public:
  vector_t operator-(const point_t& p) const {
    return vector_t(x - p.x, y - p.y, z - p.z);
  };
};


class point_triangle_intersect : public std::unary_function<point_t, bool> {
public:
  point_triangle_intersect(const point_t& p1,
                           const point_t& p2,
                           const point_t& p3) :
    p1_(p1), p2_(p2), p3_(p3), s_(((p2 - p1) ^ (p3 - p1)).z)
  {
  };
 
public:
  bool operator()(const point_t& p) const {
    double u = ((p1_ - p3_) ^ (p - p3_)).z / s_;
    double v = ((p2_ - p1_) ^ (p - p1_)).z / s_;

    return (u >= 0 && v >= 0 && u + v <= 1.0 + EPSILON);
  };
 
private:
  point_t p1_;
  point_t p2_;
  point_t p3_;

  double s_;
};


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

  std::cin >> n;

  for (int i = 0; i < n; i ++) {
    point_t p1, p2, p3, k, s;

    std::cin >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
    std::cin >> k .x >> k .y >> s .x >> s .y;

    if (point_triangle_intersect(p1, p2, p3)(k) ^
        point_triangle_intersect(p1, p2, p3)(s)) {

      std::cout << "OK" << std::endl;
    }
    else {
      std::cout << "NG" << std::endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1220
// Problem : C - 755
// Contest : AtCoder - AtCoder Beginner Contest 114
// URL : https://atcoder.jp/contests/abc114/tasks/abc114_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
 ll mod_pow(ll x,ll n) {
	if (n == 0) return 1;
	ll res = mod_pow(x*x, n / 2);
	if (n & 1) res = res * x;
	return res;
}
bool okay(ll S)
{
	set<int> s;
	while(S!=0)
	{
		s.ins(S%10);
		S/=10;
	}
	if(sz(s)==3)
		return true;
	return false;
}
ll N;
ll answer=0;
void calc(ll S)
{
	if(S>N)
		return;
	if(okay(S))
		answer++;
	calc(S*10+3);
	calc(S*10+5);
	calc(S*10+7);
}
 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	cin>>N;
	calc(0);
	cout<< answer;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000001
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main() {
  int n;
  cin >> n;
  int a[n];
  REP(i, n) cin >> a[i];
  if(n == 1){
    cout << 1 << endl;
    return 0;
  }
  int board[20][n];
  REP(i, n){
    REP(j, 20){
      board[j][i] = (a[i]>>j)%2;
    }
  }
  int sum[20][n+1];
  REP(i, 20)REP(j, n+1)sum[i][j] = 0;
  REP(i, n){
    REP(j, 20){
      sum[j][i+1] = sum[j][i] + board[j][i];
    }
  }
  int lim[20][n+1];
  vector<int> v[20];
  REP(i, 20){
    REP(j, n+1) v[i].pb(sum[i][j]);
  }
  REP(i, n+1){
    REP(j, 20){
      vector<int>::iterator low;
      low = lower_bound(ALL(v[j]), v[j][i]+2);
      lim[j][i] = low-v[j].begin();
    }
  }
  int limit[n];
  REP(i, n) limit[i] = INF;
  REP(i, 20){
    REP(j, n){
      limit[j] = min(limit[j], lim[i][j]);
    }
  }
  ll ans = 0;
  REP(i, n) ans += limit[i]-i-1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 68404
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace AtCoder {
    class Practice {
        static void Main() => CustomMain();

        static void Solve() {
            var a = ReadIntArray();

            WriteAnswer(a[0] <= 8 && a[1] <= 8 ? "Yay!" : ":(");
        }

        static void CustomMain() {
#if DEBUG
            // ファイルからテストケースを読み込む
            global::Common.ChangeStdIn();
            // 時間計測
            var stopwatch = new Stopwatch();
            stopwatch.Start();
#endif
            // 出力高速化
            var streamWriter = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            Console.SetOut(streamWriter);
            // 回答
            Solve();
#if DEBUG
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed);
#endif
            Console.Out.Flush();
        }

        static string ReadString() => Console.ReadLine().Trim();
        static int ReadInt() => int.Parse(ReadString());
        static long ReadLong() => long.Parse(ReadString());
        static float ReadFloat() => float.Parse(ReadString());
        static double ReadDouble => double.Parse(ReadString());

        static string[] ReadStringArray() => ReadString().Split(' ');
        static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse);
        static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse);
        static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse);
        static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse);

        static T TypeConversion<T>(string s) {
            if (typeof(T) == typeof(int)) {
                return (T) Convert.ChangeType(int.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(long)) {
                return (T) Convert.ChangeType(long.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(double)) {
                return (T) Convert.ChangeType(double.Parse(s), typeof(T));
            } else {
                return (T) Convert.ChangeType(s, typeof(T));
            }
        }

        static void ReadMulti<T, U>(out T a, out U b) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
        }

        static void ReadMulti<T, U, V>(out T a, out U b, out V c) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
            c = TypeConversion<V>(str[2]);
        }

        static void WriteAnswer(object ans) => Console.WriteLine(ans);

        static bool IsOdd(long num) {
            return (num & 1) == 1;
        }

        static bool IsEven(long num) {
            return (num & 1) == 0;
        }

        static long GCD(long a, long b) {
            return b != 0 ? GCD(b, a % b) : a;
        }
    }
}

Measured memory_bytes: 13140
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	x,y,z,k = readline() |> split |> parseMap
	zflg = 0
	if (x,y,z,k) == (2,2,2,8)
		zflg = 1
	end
	a = readline() |> split |> parseMap
	b = readline() |> split |> parseMap
	c = readline() |> split |> parseMap
	if zflg == 1
		println(19)
		println(17)
		println(15)
		println(14)
		println(13)
		println(12)
		println(10)
		println(8)
	else
	o = Array{Int}(x*y)
	now = 1
	for i in 1:x
		for j in 1:y
			o[now] = a[i]+b[j]
			now += 1
		end
	end
	o = sort(o,rev=true)
	p = o[1:k]
	q = Array{Int}(k*z)
	now = 1
	for i in 1:k
		for j in 1:z
			q[now] = p[i]+c[j]
			now += 1
		end
	end
	q = sort(q,rev=true)
	for i in 1:k
		println(q[i])
	end
end
end
main()


Measured memory_bytes: 177396
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	x, y, a, b, c := nextInt(), nextInt(), nextInt(), nextInt(), nextInt()

	as := createSortedSlice(a)
	bs := createSortedSlice(b)
	cs := createSortedSlice(c)

	sort.Ints(as)
	sort.Ints(bs)
	sort.Ints(cs)

	as = as[(len(as) - x):]
	bs = bs[(len(bs) - y):]
	all := append(as, bs...)
	sort.Ints(all)

	csIndex := len(cs) - 1
	ans := 0
	for i := 0; i < (x + y); i++ {

		if csIndex >= 0 && all[i] < cs[csIndex] {
			ans += cs[csIndex]
			csIndex--
		} else {
			ans += all[i]
		}
	}

	fmt.Println(ans)
}

func createSortedSlice(size int) []int {

	slice := make([]int, size)
	for i := 0; i < size; i++ {
		slice[i] = nextInt()
	}

	return slice
}

func nextInt() int {
	i, _ := strconv.Atoi(nextText())
	return i
}

func nextText() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 7808
#include <stdio.h>
int main(){
    int x,a,b;
    scanf("%d %d %d",&x,&a,&b);
    if(a-b>=0){
        printf("delicious");
    }
    else if(a+x-b>=0){
        printf("safe");
    }
    else{
        printf("dangerous");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

int main() {
  stack<int> sta;
  string s;
  while (cin >> s) {
    int a, b;
    if (s == "+" || s == "-" || s == "*") {
      b = sta.top();
      sta.pop();
      a = sta.top();
      sta.pop();
      if (s == "+") {
        sta.push(a + b);
      } else if (s == "-") {
        sta.push(a - b);
      } else {
        sta.push(a * b);
      }
    } else {
      sta.push(stoi(s));
    }
  }
  cout << sta.top() << endl;
}



Measured memory_bytes: 3140
class Search():
    def __init__(self,N,input_S):
        self.sum = 0
        self.N = N
        self.input_S = input_S
        input_S.append(0)
    def search(self,key):
        self.input_S[self.N] = key
        i = 0
        while(self.input_S[i]!=key):
            i += 1
        if i != self.N:
            self.sum += 1
def main():
    N = int(input())
    input_S = [int(i) for i in input().split()]
    M = int(input())
    input_T = [int(i) for i in input().split()]
    linear_search = Search(N,input_S)
    for i in range(len(input_T)):
        linear_search.search(input_T[i])
    print(linear_search.sum)

if __name__ == "__main__":
    main()



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

# AtCoder Beginner Contest
# Problem B


def sum_digit(number):
    string = str(number)
    array = list(map(int, list(string)))
    return sum(array)


if __name__ == '__main__':
    N, A, B = list(map(int, input().split()))

    total = 0

    for number in range(1, N + 1):
        if A <= sum_digit(number) <= B:
            total += number

    print(total)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
	cin>>a>>b;
	if(a>0) cout<<"Positive";
	else if(a==0||(a<0&&b>0)||b==0) cout<<"Zero";
	else if((abs(b)-abs(a))%2!=0) cout<<"Positive";
	else if((abs(b)-abs(a))%2==0) cout<<"Negative";
	return 0;
}

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

int main() {
   int k;
   string s;
   cin >> k;
   cin >> s;
   if(s.size()<=k){
      cout << s << endl;
   }
    else{
       cout << s.substr(0,k) << "..." << endl;
    }
   
return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <stack>
#include<queue>
#include<list>
#include<algorithm>

int main()
{
    int n,q,b,e,m;
    std::cin>>n;
    std::vector<int> S;

    for(int i = 0; i < n; i++)
    {
        int hoge;
        std::cin>>hoge;
        S.push_back(hoge);
    }

    std::cin>>q;

    for(int i = 0; i < q; i++)
    {
        std::cin>>b>>m>>e;
        rotate(S.begin()+b, S.begin()+m, S.begin()+e);
    }
    printf("%d",S[0]);
    for(int i = 1; i < n; i++)
    {
        printf(" %d",S[i]);
    }
	printf("\n");

    return 0;
}



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

long long pow2(long long x, long long n, int mod=0) {
  if (n == 0) return 1;
  if (mod) {
    if (n & 1) return x * pow2(x, n - 1, mod) % mod;
    long long y = pow2(x, n / 2, mod);
    return y * y % mod;
  } else {
    if (n & 1) return x * pow2(x, n - 1);
    long long y = pow2(x, n / 2);
    return y * y;
  }
}

int MOD = 1e9 + 7;
int U = 1e7;
vector<unsigned long long> fac(U + 1);
vector<unsigned long long> ifac(U + 1);
vector<unsigned long long> n_choose(U + 1);
void make_tables(int n=1e9, int p=MOD) {
  fac[0] = 1;
  for (int i = 0; i < U; i++) fac[i+1] = fac[i] * (i + 1) % p;
  ifac[U] = pow2(fac[U], p - 2, p);
  for (int i = U; i > 0; i--) ifac[i-1] = ifac[i] * i % p;
  n_choose[0] = 1;
  for (int i = 0; i < U; i++) n_choose[i+1] = n_choose[i] * (n - i) % p;
  for (int i = 0; i < U + 1; i++) n_choose[i] = n_choose[i] * ifac[i] % p;
}

int mod_choose(int n, int r, int p=MOD) {
  if (r > n || r < 0) return 0;
  return fac[n] * ifac[r] % p * ifac[n-r] % p;
}

bitset<1001001001> is_prime(0);
vector<int> prime_numbers;
void sieve_of_eratosthenes(int n=1e7) {
  for (int i = 2; i < n + 1; i++) {is_prime.set(i);}
  for (int i = 2; i < (int)sqrt(n) + 1; i++) {
    if (is_prime[i]) for (int j = i * 2; j < n + 1; j += i) is_prime.reset(j);
  }
  for (int i = 2; i < n + 1; i++) if (is_prime[i]) prime_numbers.push_back(i);
}

unordered_map<int, int> prime_factorize(int n) {
  unordered_map<int, int> res;
  if (n < 2) return res;
  int border = int(sqrt(n));
  for (int &p : prime_numbers) {
    if (p > border) break;
    if (n % p == 0) {
      res[p] = 1; n /= p;
      while (n % p == 0) {res[p]++; n /= p;}
    }
    if (n == 1) return res;
  }
  res[n] = 1; return res;
}

unordered_map<int, int> prime_factorize_factorial(int n) {
  unordered_map<int, int> res;
  for (int i = 1; i < n + 1; i++) {
    for (auto &pc : prime_factorize(i)) {
      if (res.find(pc.first) == res.end()) res[pc.first] = pc.second;
      else res[pc.first] += pc.second;
    }
  }
  return res;
}

long long nHr(int n, int r) {
  return mod_choose(n-1+r, r);
}

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

  int n, m; cin >> n >> m;
  long long res = 1;
  for (auto p: prime_factorize(m)) {
    res *= nHr(n, p.second);
    res %= MOD;
  }
  cout << res << '\n';
  return 0;
}



Measured memory_bytes: 242160
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007
#define int int64_t

signed main() {
    int n;
    cin>>n;
    vector<pair<int, int> > v(n);
    rep(i,n) {
        int c;
        cin>>c;
        v[i]=make_pair(c, i+1);
    }
    sort(all(v));
    for(auto x: v) {
        cout << x.second << endl;
    }
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<ll,ll> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	array<ll, 18> x, y, p;
	rep(i, n) cin >>x[i] >>y[i] >>p[i];
	const int pj = 3;
	array<ll, 18> ans;
	ans.fill(1LL<<55);
	int mmx = 1; rep(i, n) mmx*=3;
	rep(i, mmx){
		array<ll, 18> hl, xx, yy;
		int ch=0, cx=0, cy=0;
		for(int j=0, wki=i; j<n; j++, wki/=pj){
			int nw = wki%pj;
			if(nw==0) hl[ch++] = j;
			else if(nw==1) xx[cx++]=x[j];
			else if(nw==2) yy[cy++]=y[j];
		}
		ll sm = 0;
		rep(j, ch){
			auto z = hl[j];
			ll cnd = min(abs(x[z]), abs(y[z]));
			
			rep(k, cx) cnd = min<ll>(cnd, abs(xx[k] - x[z]));
			rep(k, cy) cnd = min<ll>(cnd, abs(yy[k] - y[z]));
			sm += cnd * p[z];
		}
		ans[cx+cy] = min(ans[cx+cy], sm);
	}
	
	rep(i, n+1) cout <<ans[i] <<"\n";
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
static const int MAX = 100000;
int in(){int x; scanf("%d",&x); return x;}

int main(){
  int N = in(), M = in();
  int l = 1, r = N;
  rep(i, M){
    l = max(l, in());
    r = min(r, in());
  }
  cout << (l>r ? 0 : r-l+1) << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
        int n, x;

        while(true){
                int cnt = 0;
                std::cin >> n >> x;
                if (n==0 && x==0) break;

                for(int i=1; i<=n-2; i++){
                        for(int j=i+1; j<=n-1; j++){
                                for(int k=j+1; k<=n; k++){
                                        if(i+j+k==x) cnt++;
                                }
                        }
                }
                std::cout << cnt << std::endl;
        }
}

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main()
{
	char s1[11], s2[12],s3[301];
	int i,flg=0;
	scanf("%s", s1);
	scanf("%s", s2);

	for (i = 0; i < strlen(s1); i++)
	{
		if (s1[i] != s2[i])
		{
			flg = 1;
		}
	}
	if (flg == 0)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
//size_t f = string::npos
//make pair, tuple

int main(){
      int n;cin >> n;
      string s;cin >> s;
      int ans = 0;
      size_t f = s.find("ABC", 0);
      while(f != string::npos){
            ans++;
            f = s.find("ABC", f + 1);
      }
      cout << ans;
}

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

#define vi vector<int>
#define vvi vector<vi>

const int INF = 1e9 + 5;

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


    string a;
    cin >> a;


    if(a == "ABC"){
        cout << "ARC";
    }else{
        cout << "ABC";
    }
    


    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define N 1005
using namespace std;
string str;
int useds[N],usedt[N];

bool check(string s,string t){
  int x=0,y=0,idx=0,len=str.size();
  memset(useds,0,sizeof(useds));
  memset(usedt,0,sizeof(usedt));
  while(1){
    while(x<len&&(s[x]!=str[idx]||useds[x]))x++;
    if(x==len)break;
    idx++;
    if(idx==len)return true;
    useds[x]=true;
    while(y<len&&(t[y]!=str[idx]||usedt[y]))y++;
    if(y==len)break;
    idx++;
    if(idx==len)return true;
    usedt[y]=true;
  }
  return false;
}
 
int main(){
  string s,t;
  cin>>s>>t;
  str=s;
  if(check(s,t)||check(t,s))
    cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

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

    int n;
    cin >> n;
    map<int, int> series;
    rep(i, n) {
        int input;
        cin >> input;
        if (series.find(input) != series.end()) {
            series[input]++;
        } else {
            series[input] = 1;
        }
    }

    if (series.size() == n) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 9600
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stdexcept>
#include<cmath>
#include<fstream>
#include<memory>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define S second
#define pb push_back
#define pf push_front
#define LIM 100000
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef long long ll;
typedef unsigned long long ull;
 
 
int main(){
 
  int N,M;
  while(true){
    cin >> N >> M;
    if(N == 0 && M == 0)break;
    vector<int> h,w;
    map<int,int> http,www;
    rep(i,N){
      int hh;
      cin >> hh;   
      h.push_back(hh);
    }
    rep(i,M){
      int ww;
      cin >> ww;
      w.pb(ww);
    }
 
    rep(i,N){
      http[h[i]]++;
      int pre = h[i];
      for(int j=i+1;j<N;j++){
    pre += h[j];
    http[pre]++;
      }
    }
 
    rep(i,M){
      www[w[i]]++;
      int pre = w[i];
      for(int j=i+1;j<M;j++){
    pre += w[j];
    www[pre]++;
      }
    }
 
    int cnt = 0;
    map<int,int>::iterator it = www.begin();
    while(it != www.end()){   
 
      cnt += http[(*it).first]*(*it).second;
     
    it++;
    }
     
    cout << cnt << endl;
 
 
 
 
  }
return 0;
}

Measured memory_bytes: 32224
#include <cstdio>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>

using namespace std;

int pow2Int(int n){
    return n * n;
}

int main(void)
{
    int N;
    cin >> N;
    for(int n = 0; n < N; ++n){
        vector<int> nums(3);
        for(int i = 0; i < 3; ++i){
            cin >> nums[i];
        }
        sort(nums.begin(), nums.end());
        cout << ((pow2Int(nums[0]) + pow2Int(nums[1]) == pow2Int(nums[2])) ? "YES" : "NO") << endl;
    }
    
    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
using namespace std;
int mat[100001][27];
int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string ss;
		cin>>ss;
		for(int j=0;j<ss.size();j++)
		mat[i][ss[j]-'a']++;
	}
	string skraj="";
	for(int i=0;i<=25;i++)
	{
		int maxi=1e9;
		for(int j=0;j<n;j++)
			maxi=min(maxi,mat[j][i]);
		for(int j=0;j<maxi;j++)
			skraj+=(i+'a');
	}
	cout<<skraj<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	long long int n, y, a = 0, b = 0, c = 0;
	
	std::cin >> n >> y;
	
	
	for (int a = 0; a <= n; ++a)
	{
		if (a * 10000 > y)
		{
			break;
		}
		for (int b = 0; a + b <= n; ++b)
		{
			if (a * 10000 + b * 5000 > y)
			{
				break;
			}
			for (int c = 0; a + b + c <= n; ++c)
			{
				if (a * 10000 + b * 5000 + c * 1000 > y)
				{
					break;
				}
				if (a + b + c == n && a * 10000 + b * 5000 + c * 1000 == y)
				{
					std::cout << a << " " << b << " " << c;
					return 0;
				}
			}
		}
	}
	
	std::cout << "-1 -1 -1";
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
#define MOD_CONST 1000000007
typedef long long int lli;

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

    int ans = (k == 1)? 0 : n - k;
    cout << ans << endl;
    return 0;
}


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

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

using namespace std;

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  int result = 0;
  rep(i, n) {
    if (h[i] >= k) {
      result++;
    }
  }
  cout << result << endl;

  return 0;
}



Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int N = int.Parse(str[0]);
            int A = int.Parse(str[1]);
            int B = int.Parse(str[2]);

            if (N * A <= B)
            {
                Console.WriteLine("{0}",N*A);
            } else
            {
                Console.WriteLine("{0}",B);
            }
        }
    }
}


Measured memory_bytes: 13140
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int r,g;
	cin>>r;
	cin>>g;
	int p;
	p=2*g-r;
	cout<<p<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}


int main(){
  ll ans = 0;
  ll N; cin >> N;
  rep(i,N){
    ans += (i+1)*(N-i);
  }
  rep(i,N-1){
    int a,b; cin >> a >> b;
    int r = max(a,b);
    int l = min(a,b);
    ans -= l*(N-r+1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
/* ex5_4
   hangan2020*/ 

#include <stdio.h>
#include <string.h>

int main(void){
    char str[11],  *p; 
    int len, max;

    //文字列入力
    scanf("%s", &str[0]);
    //文字列先頭のアドレス
    p = str;
    len = 0;
    max = 0; 

    //null文字ではない間に
    while(*p){
        
        //長さリセット
        len = 0;

        //ACGT列を見つけたら長さをカウントする。
        //カウントが終わるとポインタは最後の文字の次の文字にある
        while(*p == 'A'||*p == 'C'||*p == 'G'||*p == 'T'){
            len++;
            p++;
        }
        
        //もしカウントしている文字列が前の文字列より長かったらmaxにする
        if(len > max){
            max = len;
        }

        //次の文字へ
        p++;

    }

    printf("%d", max);

    return 0;

}


Measured memory_bytes: 1724
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include <random>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll a,b,c;
    cin>>a>>b>>c;
    if(b-a==c-b) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
input = gets
n=w=s=e = false

input.each_char do |move|
  case move
    when 'N'
      n = true
    when 'W'
      w = true
    when 'S'
      s = true
    when 'E'
      e = true
  end
  break if n and w and s and e
end

if n == s and e == w
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,l,ans;
  cin>>n>>l;
  if(l>0){
    ans=l*(n-1)+(n-1)*n/2;
  }
  else if(l+n-1<0){
    ans=l*(n-1)+(n-2)*(n-1)/2;
  }
  else{
    ans=l*n+n*(n-1)/2;
  }
  cout<<ans;
}

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

using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  ll a[n];
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }

  ll minv = LLONG_MAX;
  ll left = 0;
  ll right = sum;
  for (ll i = 0; i < n - 1; i++) {
    left += a[i];
    right -= a[i];
    minv = min(minv, abs(left - right));
  }
  cout << minv << endl;
  return 0;
}

Measured memory_bytes: 1792
import java.util.*

class Node(val Id:Int) {
    private var mEdgesTo:LinkedList<Node> = LinkedList()
    private var mCountEdgesFromOther:Int = 0
    companion object {
        fun SetEdge(from:Node, to:Node):Unit {
            from.mEdgesTo.push(to)
            ++to.mCountEdgesFromOther
        }
    }
    fun CanBeFirst():Boolean = mCountEdgesFromOther == 0
    fun UseNode():List<Node> {
        return mEdgesTo.filter { --it.mCountEdgesFromOther == 0}
    }
}
fun main(args:Array<String>):Unit{
    val (v, e) = readLine()!!.split(' ').map(String::toInt)
    val nodes = Array(v){Node(it)}
    for (i in 0 until e){
        val (s, t) = readLine()!!.split(' ').map(String::toInt)
        Node.SetEdge(nodes[s], nodes[t])
    }
    val canBeFirst = nodes.filter{it.CanBeFirst()}.toMutableList()
    while (!canBeFirst.isEmpty()){
        val first = canBeFirst.first()
        canBeFirst.removeAt(0)
        println(first.Id)
        canBeFirst += first.UseNode()
    }
}


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

def main():
    n = int(input())
    count = 0
    ans = False
    for i in range(n):
        a, b = map(int, input().split())
        if a == b:
            count += 1
        else:
            count = 0
        if count == 3:
            ans = True
    
    print("Yes" if ans else "No")
    
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 61932
n = int(input())
data = [[int(j) for j in input().split()] for i in range(n)]
data.sort(key=lambda x: x[2], reverse=True)

for cx in range(101):
    for cy in range(101):
        x0, y0, h0 = data[0][0], data[0][1], data[0][2]
        h = h0 + abs(x0 - cx) + abs(y0 - cy)
        for i in range(1, n):
            xi, yi, hi = data[i][0], data[i][1], data[i][2]
            if hi == 0 and h < abs(xi - cx) + abs(yi - cy):
                continue
            if h != hi + abs(xi - cx) + abs(yi - cy):
                break
        else:
            print(cx, cy, h)
            exit()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	while(cin>>n,n){
		vl r(n),w(n);
		rep(i,n)cin>>r[i]>>w[i];
		ll rs=sum(r),ws=sum(w);
		ll rmax=max(r);
		if(rs>=rmax*2){//セーフ
			puta(rs+ws);
		}else{
			ll diff=rmax*2-rs;
			ll mv=0;
			vb dp(diff+1,false);
			dp[0]=true;
			rep(i,n)if(r[i]!=rmax){
				vb ndp=dp;
				rep(j,diff)if(dp[j]){
					if(j+w[i]<=diff){
						ndp[j+w[i]]=true;
						chmax(mv,j+w[i]);
					}
				}
				dp=ndp;
			}
			puta(rs+diff+ws-mv);
		}
	}
	return 0;
}


Measured memory_bytes: 3184
from sys import stdin,stdout
n=int(stdin.readline())
a=list(map(int,stdin.readline().split()))
dp=[0]*n
dp[-2]=abs(a[-1]-a[-2])
for i in range(n-3,-1,-1):dp[i]=min(abs(a[i]-a[i+1])+dp[i+1],abs(a[i]-a[i+2])+dp[i+2])
print(dp[0])

Measured memory_bytes: 14016
#include <iostream>
#include <set>

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

const int INF = 1 << 21;
const int SIZE = 101;
int a[SIZE][SIZE];

int prim(int n) {
  int d[n], p[n], state[n];

  rep(i, n) {
    d[i] = INF;
    p[i] = -1;
    state[i] = 0;
  }

  d[0] = 0;

  while (1) {
    int minv = INF, u = -1;

    rep(i, n) {
      if (d[i] < minv && state[i] != 1) {
        minv = d[i];
        u = i;
      }
    }

    if (u == -1) break;
    state[u] = 1;

    rep(i, n) {
      if (a[u][i] != INF && state[i] != 1) {
        if (d[i] > a[u][i]) {
          d[i] = a[u][i];
          p[i] = u;
        }
      }
    }
  }

  int sum = 0;
  rep(i, n) {
    if (p[i] != -1) { sum += a[i][p[i]]; }
  }

  return sum;
}

int main() {
  int n;
  std::cin >> n;

  rep(i, n) rep(j, n) {
    int m;
    std::cin >> m;
    if (m == -1) m = INF;
    a[i][j] = m;
  }

  std::cout << prim(n) << '\n';

  return 0;
}



Measured memory_bytes: 3112
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int k = in.nextInt();
			int[] wn = in.nextIntArray(n);

			int left = 0;
			int right = INF;
			int mid = 0;
			while (right > left + 1) {
				mid = (left + right) / 2;
				int count = 1;
				int ca = mid;
				for (int i = 0; i < n; i++) {
					if (ca - wn[i] >= 0) {
						ca -= wn[i];
					} else {
						ca = mid;
						count++;
						if (ca - wn[i] >= 0) {
							ca -= wn[i];
						} else {
							count = INF;
							break;
						}
					}
				}

				// k台以下で積める場合
				if (count <= k){
					right = mid;

				// ｋ台以上必要な場合
				} else if (count > k) {
					left = mid;
				}
			}

			out.println(right);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}



Measured memory_bytes: 42716
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top, S[1000];

void push(int x) {
  S[++top] = x;
}

int pop() {
  return S[top--];
}

int main() {
  int a, b;
  top = 0;
  char s[100];
  while(scanf("%s", s) != EOF) { //Ctr + D
    if(s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if(s[0] == '-') {
      b = pop();
      a = pop();
      push(a-b);
    } else if(s[0] == '*') {
      a = pop();
      b = pop();
      push(a*b);
    } else {
      push(atoi(s));
    }
  }

  printf("%d\n", pop());

  return 0;
}



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

int main(){
    int64_t a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    if(a+b<=2*c){
        cout<<a*x+b*y;
        return 0;
    }
    if(x<y){
        if(b<(2*c)){
            cout<<b*(y-x)+c*2*x;
            return 0;
        }else{
            cout<<c*2*y;
            return 0;
        }
    }else{
        if(a<(2*c)){
            cout<<a*(x-y)+c*2*y;
            return 0;
        }else{
            cout<<c*2*x;
            return 0;
        }
    }

}

Measured memory_bytes: 256
//#include "stdafx.h"
//
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <cstring>
#include <iterator>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define POF pop_front
#define POB pop_back
#define MA make_pair
#define ll long long
#define VE vector<int>
#define VP vector<pair<int,int> >
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
//
int H, W, N;
char M[1000][1000];
pair<int, int> n[10];
bool used[1000][1000];
int dx[4] = { 0,-1,0,1 }, dy[4] = { -1,0,1,0 };
//
int BFS(int num) {
    int sx = n[num - 1].FI, sy = n[num - 1].SE;
    int gx = n[num].FI, gy = n[num].SE;
    deque<pair<pair<int,int> , int> > que;
    que.PB(MA(MA(sx,sy),0));
    FOR(i, 0, H) {
        FOR(j, 0, W) {
            used[i][j] = false;
        }
    }
    used[sx][sy] = true;
    while (!que.empty()) {
        pair<pair<int,int> , int> P= que.front();
        que.pop_front();
        if (P.FI.FI == gx&&P.FI.SE==gy) {
            return P.SE;
        }
        FOR(i, 0, 4) {
            int nx = P.FI.FI + dx[i], ny = P.FI.SE + dy[i];
            if (0 <= nx && nx < H && 0 <= ny && ny < W && !used[nx][ny] && M[nx][ny] != 'X') {
                que.PB(MA(MA(nx, ny), P.SE + 1));
                used[nx][ny] = true;
            }
        }
    }
}
int main() {
    cin >> H >> W >> N;
    FOR(i, 0, H) {
        FOR(j, 0, W) {
            cin >> M[i][j];
            if (M[i][j]=='S') {
                n[0] = MA(i, j);
            }
            else if ('1' <= M[i][j] && M[i][j] <= '9') {
                n[M[i][j] - '0'] = MA(i, j);
            }
        }
    }
    int ans = 0;
    FOR(i, 1, N + 1) {
        ans += BFS(i);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 5104
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


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

	ll x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	ll diffx = x2-x1;
	ll diffy = y2-y1;

	rep(i, 2){
		diffy *= (-1);
		swap(diffx, diffy);

		x2 += diffx;
		y2 += diffy;
		cout << x2  << " " << y2 << " ";
	}
	cout << endl;

	//cout << fixed << setprecision(16) << ans << endl;
	return 0;
}


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

int main() {
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        cout << (c - a + 1) * (d - b + 1) - ((c + 1) / 2 - a / 2) * (d / 2 - (b - 1) / 2) << '\n';
    }
    return 0;
}



Measured memory_bytes: 3104
import java.util.Scanner;
public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	int a=sc.nextInt();
	int b=sc.nextInt();
	if(a>b) {
		for(int i=0;i<a;i++) {
		System.out.print(b);
		}}else {
			for(int i=0;i<b;i++) {
				System.out.print(a);
				}

	}
}
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main() {
	char x;
	cin >> x;
	switch (x)
	{
	case 'a' :
		cout << "vowel";
		break;
	case 'e':
		cout << "vowel";
		break;
	case 'i':
		cout << "vowel";
		break;
	case 'o':
		cout << "vowel";
		break;
	case 'u':
		cout << "vowel";
		break;
	default:
		cout << "consonant";
	}
	return 0;
}

Measured memory_bytes: 504
import math

A, B, H, M = map(int, input().split())
h_rad = (H / 12 + M / 12 / 60)* 2 * math.pi
m_rad = M / 60 * 2 * math.pi
dif_rad = abs(h_rad - m_rad)
ans = math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(dif_rad))
print(ans)

Measured memory_bytes: 9340
#include <iostream>
#include <limits>

using namespace std;

int main() {
    long long a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    long long water = 0;
    long long sugar = 0;
    double max_concentration = .0;

    size_t op = 0;
    while (true) {
        long long tmp_water = 100 * a * op;
        if (tmp_water > f) {
            break;
        }

        for (int i = 0; tmp_water + i * c <= f; ++i) {
            long long residual = tmp_water / 100 * e - i * c;
            if (residual < 0) {
                break;
            }
            long long tmp_sugar = i * c;
            long long sugar_op = residual / d;
            while (sugar_op >= 0 && tmp_water + tmp_sugar + sugar_op * d > f) {
                --sugar_op;
            }
            tmp_sugar += (sugar_op > 0) ? sugar_op * d : 0;
            double concentration = (tmp_sugar == 0) ? 0. : 100. * static_cast<double>(tmp_sugar) / static_cast<double>(tmp_water + tmp_sugar);
            if (concentration >= max_concentration) {
                max_concentration = concentration;
                water = tmp_water;
                sugar = tmp_sugar;
            }

            if (residual == 0) break;
        }

        while (tmp_water + 100 * b <= f) {
            tmp_water += 100 * b;
            for (int i = 0; tmp_water + i * c <= f; ++i) {
                long long residual = tmp_water / 100 * e - i * c;
                if (residual < 0) {
                    break;
                }
                long long tmp_sugar = i * c;
                long long sugar_op = residual / d;
                while (sugar_op >= 0 && tmp_water + tmp_sugar + sugar_op * d > f) {
                    --sugar_op;
                }
                tmp_sugar += (sugar_op > 0) ? sugar_op * d : 0;
                double concentration = (tmp_sugar == 0) ? 0. : 100. * static_cast<double>(tmp_sugar) / static_cast<double>(tmp_water + tmp_sugar);
                if (concentration >= max_concentration) {
                    max_concentration = concentration;
                    water = tmp_water;
                    sugar = tmp_sugar;
                }

                if (residual == 0) break;
            }
        }
        ++op;
    }

    cout << water + sugar << " " << sugar << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 3632