akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  string s;
  int gx, gy;
  cin >> s >> gx >> gy;

  int N = s.size();
  vector<int> x, y;
  int cnt = 0;
  int direct = 1;
  REP(i, N){
    if(i == N-1 && s[i] == 'F') cnt++;
    if(s[i] == 'T' || i == N-1){
      if(direct%2) x.push_back(cnt);
      else y.push_back(cnt);
      direct++;
      cnt = 0;
    }else{
      cnt++;
    }
  }

  vector<vector<bool>> xdp(x.size()+1, vector<bool>(2*N, false));
  xdp[0][N] = true;
  REP(i, x.size()){
    REP(j, 2*N){
      if(xdp[i][j]){
        xdp[i+1][j+x[i]] = true;
        if(i != 0) xdp[i+1][j-x[i]] = true;
      }
    }
  }

  vector<vector<bool>> ydp(y.size()+1, vector<bool>(2*N, false));
  ydp[0][N] = true;
  REP(i, y.size()){
    REP(j, 2*N){
      if(ydp[i][j]){
        ydp[i+1][j+y[i]] = true;
        ydp[i+1][j-y[i]] = true;
      }
    }
  }

  if(xdp[x.size()][N+gx] && ydp[y.size()][N+gy]) Yes;
  else No;

  return 0;
}

Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e2;
const int MAX_V = 1e3 * 1e2;
const int64_t INF = 2*1e9;
// (N, V) => min(w)
int64_t dp[MAX_N + 1][MAX_V + 1];
// O(VN) (V = v*N)
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    int64_t W;
    cin >> N >> W;
    vector<int64_t> w(N), v(N);
    for(int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }
    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= MAX_V; j++) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= MAX_V; j++) {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            int j_ = j + v[i];
            if(j_ <= MAX_V) {
                dp[i + 1][j_] = min(dp[i + 1][j_], dp[i][j] + w[i]);
            }
        }
    }
    int64_t ans = -1;
    for(int j = MAX_V; j >= 0; j--) {
        if(dp[N][j] <= W) {
            ans = j;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 79104
a=list(map(int, input().split()))
taka=a[0]
ao=a[1]
K=a[2]
if K==taka:
    print(0,ao)
elif K<taka:
    print(taka-K,ao)
elif K>taka and K-taka<=ao:
    print(0,ao-(K-taka))
elif K>taka and K-taka>=ao:
    print(0,0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
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;}

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

    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            ans += d[i] * d[j];
        }
    }

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


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char a,x,y;
    scanf("%c %c",&x,&y);
       if(x<y)
        a='<';
       if(x==y)
        a='=';
       if(x>y)
        a='>';
       printf("%c\n",a);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll A,B;
  cin >> A >> B;
  if(B % A == 0){
    cout << A+B;
  }
  else{
    cout << B - A;
  }
}
  

Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main()
{
    char a1,b1,c1,d1;
    int ans,a,b,c,d;
    cin>>a1>>b1>>c1>>d1;
    a=a1-'0';b=b1-'0';c=c1-'0';d=d1-'0';
    for(char i='+';i<='-';i++)
    for(char j='+';j<='-';j++)
    for(char k='+';k<='-';k++)
    {
        ans=a;
        if(i=='+') ans+=b;
        else if(i=='-') ans-=b;
        if(j=='+') ans+=c;
        else if(j=='-') ans-=c;
        if(k=='+') ans+=d;
        else if(k=='-') ans-=d;
        if(ans==7)//找到了
        {
            cout<<a<<i<<b<<j<<c<<k<<d<<"="<<ans<<endl;
            return 0;
        }
    }
}

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

int main() {
  string alpha = "zabcdefghijklmnopqrstuvwxy";
  long long n; cin >>n;
  string ret = "";
  while (n > 0) {
    int str = n % 26;
    ret = alpha[str] + ret;
    n = (n%26==0) ? n/26 -1 : n/26;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int n,q,k,b[100010];
long long a[100010],t;
vector<long long> v;
int main(){
	cin>>n>>t>>q;
	for(k=0;k<n;k++){
		cin>>a[k]>>b[k];
		if(k)if(b[k-1]==1&&b[k]==2)v.push_back((a[k-1]+a[k])/2);
	}
	while(q--){
		cin>>n;n--;
		k=lower_bound(v.begin(),v.end(),a[n])-v.begin();
		if(b[n]==1){
			if(k==v.size())cout<<a[n]+t;
			else cout<<min(a[n]+t,v[k]);
		}
		else {
			if(!k)cout<<a[n]-t;
			else cout<<max(a[n]-t,v[k-1]);
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 4396
import java.util.*;

public class Main {
  public static long MOD = (long)Math.pow(10, 9) + 7;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] kai = new long[n + 1];
    kai[0] = 1;
    for(int i = 1; i <= n; i++) {
      kai[i] = (kai[i - 1] * (long)i) % MOD;
    }
    long[] inv = new long[n + 1];
    inv[1] = 1;
    for(int i = 2; i <= n; i++) {
      inv[i] = func((long)i, MOD - 2);
    }
    long[] rui = new long[n + 1];
    rui[1] = kai[n];
    for(int i = 2; i <= n; i++) {
      rui[i] = (rui[i - 1] + (kai[n] * inv[i]) % MOD) % MOD;
    }
    long ans = 0;
    for(int i = 0; i < n; i++) {
      long a = sc.nextLong();
      long c = rui[i + 1];
      c = (c + rui[n - i] + MOD - rui[1]) % MOD;
      c = (a * c) % MOD;
      ans = (ans + c) % MOD; 
    }
    System.out.println(ans);
  }

  public static long func(long a, long x) {
    if(x == 0) return 1;
    if((x % 2) == 0) {
      long t = func(a, x / 2);
      return (t * t) % MOD;
    } else {
      return (a * func(a, x - 1)) % MOD;
    }
  }
}

Measured memory_bytes: 50664
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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



	int a,b;
	cin>>a>>b;
	a %= 500;
	if (a <= b) {
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
	return 0;
}



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

int main() {
  string S;
  cin >> S;

  if(S.at(2) == S.at(3) && S.at(4) == S.at(5)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsign-conversion"

#define NDEBUG
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
using uint = unsigned int;
using usize = std::size_t;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template<typename T> constexpr T popcount(const T u) { return u ? static_cast<T>(__builtin_popcountll(static_cast<u64>(u))) : static_cast<T>(0); }
template<typename T> constexpr T log2p1(const T u) { return u ? static_cast<T>(64 - __builtin_clzll(static_cast<u64>(u))) : static_cast<T>(0); }
template<typename T> constexpr T msbp1(const T u) { return log2p1(u); }
template<typename T> constexpr T lsbp1(const T u) { return __builtin_ffsll(u); }
template<typename T> constexpr T clog(const T u) { return u ? log2p1(u - 1) : static_cast<T>(u); }
template<typename T> constexpr bool ispow2(const T u) { return u and (static_cast<u64>(u) & static_cast<u64>(u - 1)) == 0; }
template<typename T> constexpr T ceil2(const T u) { return static_cast<T>(1) << clog(u); }
template<typename T> constexpr T floor2(const T u) { return u == 0 ? static_cast<T>(0) : static_cast<T>(1) << (log2p1(u) - 1); }
template<typename T> constexpr bool btest(const T mask, const usize ind) { return ((static_cast<u64>(mask) >> ind) & static_cast<u64>(1)); }
template<typename T> constexpr T bcut(const T mask, const usize ind) { return ind == 0 ? static_cast<T>(0) : static_cast<T>((static_cast<u64>(mask) << (64 - ind)) >> (64 - ind)); }
template<typename T> bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); }
template<typename T> bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); }
constexpr unsigned int mod                  = 1000000007;
template<typename T> constexpr T inf_v      = std::numeric_limits<T>::max() / 4;
template<typename Real> constexpr Real pi_v = Real{3.141592653589793238462643383279502884};
template<typename T>
T read()
{
    T v;
    return std::cin >> v, v;
}
template<typename T>
std::vector<T> read_vec(const std::size_t size)
{
    std::vector<T> v(size);
    for (auto& e : v) { std::cin >> e; }
    return v;
}
template<typename... Types>
auto read_vals() { return std::tuple<std::decay_t<Types>...>{read<Types>()...}; }
#define SHOW(...) static_cast<void>(0)
template<typename T>
std::vector<T> make_v(const std::size_t size, T v) { return std::vector<T>(size, v); }
template<class... Args>
auto make_v(const std::size_t size, Args... args) { return std::vector<decltype(make_v(args...))>(size, make_v(args...)); }
int main()
{
    const auto n = read<usize>();
    using pll    = std::pair<ll, ll>;
    pll op       = {1, 0};
    for (usize i = 0; i < n; i++) {
        const auto q = read<usize>();
        const auto x = read<ll>();
        if (q == 1) {
            op.first *= x, op.second *= x;
        } else if (q == 2) {
            op.second += x;
        } else {
            op.second -= x;
        }
    }
    std::cout << -op.second << " " << op.first << std::endl;
    return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
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; }

int main(){
	ll a,b; cin>>a>>b;
	ll k; cin>>k;
	set<ll> ans;
	rep(i,a,min(b+1,a+k)){
		ans.insert(i);
	}
	per(i,b+1,max(b-k+1,a)){
		ans.insert(i);
	}
	for(auto i:ans){
		cout<<i<<endl;
	}
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
N = int(input())
S = [input().rstrip() for _ in range(N)]
c = [0]*4
for s in S:
    if s=='AC':
        c[0]+=1
    elif s=='WA':
        c[1]+=1
    elif s=='TLE':
        c[2]+=1
    else:
        c[3]+=1

print('AC x {0}'.format(c[0]))
print('WA x {0}'.format(c[1]))
print('TLE x {0}'.format(c[2]))
print('RE x {0}'.format(c[3]))

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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const int MOD = 1000000007;
const int INF = 1000000000;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const int MAX = 200101;
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;
    }
}

long long 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;
}


int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);
    // for file input
    /* ifstream in("input.txt");
    ifstream in("input.txt"); */

    int n, k;
    cin >> n >> k;
    vector<llong> cumf(n + 1), cumb(n + 1);
    cumf[0] = 0;
    cumb[0] = n;
    rep(i, n) {
        cumf[i + 1] += cumf[i] + i + 1;
        cumb[i + 1] += cumb[i] + n - (i + 1);
    }
    // rep(i, n + 1) cout << cumf[i] << " ";
    // cout << endl;

    llong res = 0;
    for (llong i = k; i <= n + 1; ++i) {
        res += cumb[i - 1] - cumf[i - 1] + 1;
        res %= MOD;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 6368
#include <bits/stdc++.h> // {{{
// clang-format off
#define ARG4(_1, _2, _3, _4, ...) _4
#define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define REP(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i, 0, a)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i)
#define ALL(c) (c).begin(), (c).end()
#define pb emplace_back
#define em emplace
#define fi first
#define se second
#define USE1(...) template <typename __VA_ARGS__> inline
#define USE2(T, ...) USE1(T, typename __VA_ARGS__)
#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
 
using ll = long long;
template<typename T> using vec = std::vector<T>;
USE2(T,U)bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE2(T,U)bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE1(T=int)T in(){T x;std::cin>>x;return x;}
USE2(T=int,V=vec<T>)V reserved(int n){V v;v.reserve(n);return v;}
USE1(T=int)vec<T>in(int n){auto v=reserved<T>(n);rep(i,n)v.pb(in<T>());return v;}
USE2(T,U=std::pair<T,int>)vec<U>enume(const vec<T>&x,int s=0){int N=x.size();auto v=reserved<U>(N);rep(i,N)v.pb(x[i],s+i);return v;}
USE1(T)vec<T>ndvec(T v,int n){return vec<T>(n,v);}
USE2(T,...Ts)auto ndvec(T v,int n,Ts...ns)->vec<decltype(ndvec(v,ns...))>{return ndvec(ndvec(v,ns...),n);}
USE1(T)void pr(T x){std::cout<<x<<'\n';}
USE2(T,...Ts)void pr(T x,Ts...xs){std::cout<<x<<' ';pr(xs...);}
USE2(T,U)void prif(bool b,T t,U f){if(b)pr(t);else pr(f);}
USE1(T=int)T rd(){T x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;}
USE1(T=int)void wr(T x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);}
// clang-format on
// }}}
struct IoSetup { // {{{
  IoSetup() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.precision(20);
    std::cout.setf(std::ios::fixed);
  }
} iosetup; //}}}
using namespace std;
const int inf = 1001001001;
const ll infl = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};

signed main() {
  ll N = in<ll>();
  int mini = inf;
  for (ll A = 1; A * A <= N; A++) {
    if (N % A) continue;
    ll B = N / A;
    chmin(mini, to_string(B).size());
  }
  pr(mini);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);
int main() {
    cin>>Q;
    rep(_, Q){
        cin>>N;
        vec k(N), p(N), ord(N), left(N + 1), right(N + 1);
        rep(i, N + 1) {
            left[i] = right[i] = i;
        }
        ll res = 0;
        rep(i,N){
            cin>>k[i]>>A>>B;
            p[i] = A - B;
            ord[i] = i;
            res += B;
        }
        sort(ALL(ord), [&](int x, int y){
            return p[x] > p[y];
        });
        rep(i,N){
            int id = ord[i], place = k[id];
            if(p[id] <= 0) break;
            while(place != left[place]) place = left[place] = left[left[place]];
            if(place != 0){
                res += p[id];
                left[place] = place - 1;
            }
        }
        Rrep(i, N){
            int id = ord[i], place = k[id];
            if(p[id] >= 0) break;
            while(place != right[place]) place = right[place] = right[right[place]];
            if(place != N){
                right[place] = place + 1;
            }else{
                res += p[id];
            }
        }
        cout<<res<<endl;
    }
}


Measured memory_bytes: 11084
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,c=0,ans,i,j,k,flag;
    cin>>n;
    ans=n;
    for(i=0;i<=n;i++)
    {
        c=0;
        j=i;
        while(j!=0)
        {
             c+=j%6,j/=6;
        }

        j=n-i;
        while(j!=0)
        {
            c+=j%9,j/=9;
        }

        if(ans>c)
            ans=c;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
NK = input().split(' ')
N = int(NK[0])
K = int(NK[1])
An = sorted(list(map(int,input().split(' '))))
Fn = sorted(list(map(int,input().split(' '))),reverse=True)
An_s = sum(An)

min_time = -1 #middle_time = 0を含めるので -1
max_time = An[N-1] * Fn[0] #最大でかかる時間
x_cadidate = An[N-1] * Fn[0] #xの最小の候補
middle_time = -1
range_n = range(N)
#init_list = [0]*N
while True:
    # max_time+1は max_time=0まで求めるため
    middle_time = (min_time + max_time)//2 #二部探索ように 最大と最小の半分を考える この時 middle_time An[i] * Fn[i]の取りうる最大として考える 
    #new_list = init_list
    sum_ax = 0
    for i in range_n:
        ax = middle_time//Fn[i] # An[i] * Fn[i] = x < middle_time より
        if ax < An[i]:
            sum_ax += ax
        else:
            sum_ax += An[i]
    if  min_time+1 == max_time: #二部探索で全てを探索したら終了 
        break
    elif An_s - sum_ax <= K:
        if x_cadidate > middle_time:
            x_cadidate = middle_time 
        max_time = middle_time   #もう少し middle_timeを減らせる
    else:
        min_time = middle_time   #もう少し middle_timeは大きい

print(x_cadidate)

Measured memory_bytes: 119004
#include<bits/stdc++.h>
using namespace std;
 
#define bstN 500000
struct bst{
  int size;
  int t[bstN];
  int lc[bstN];
  int rc[bstN];
    
  void init(){
    size=0;
  }
    
  void insert(int v){
    int i=0;
    while(0<=i&&i<size){
      int& child=(v<t[i]?lc[i]:rc[i]);
      if(child==-1)child=size;
      i=child; 
    }
    lc[size]=rc[size]=-1;
    t[size++]=v;
  }
 
  bool find(int v){
    int i=0;
    while(0<=i&&i<size){
      if(t[i]==v)return true;
      i=(v<t[i]?lc[i]:rc[i]);      
    }
    return false;
  }
   
  void preord(int pos){
    if(pos==-1||pos==size)return;
    preord(lc[pos]);
    printf(" %d",t[pos]);
    preord(rc[pos]);
  }
    
  void inord(int pos){
    if(pos==-1||pos==size)return;
    printf(" %d",t[pos]);
    inord(lc[pos]);
    inord(rc[pos]);
  }
};
  
  
bst T;
  
int main(){
  T.init();
  int n,a;
  char str[100];
  scanf("%d",&n);
    
  while(n--){
    scanf("%s",str);
    if(str[0]=='i'){
      scanf("%d",&a);
      T.insert(a);
    }else if(str[0]=='f'){
      scanf("%d",&a);
      if(T.find(a))printf("yes\n");
      else printf("no\n");      
    }else{
      T.preord(0);
      printf("\n");
      T.inord(0);
      printf("\n");
    }
  }
  
  return 0;
}


Measured memory_bytes: 7800
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		int n = 0;
		int count;
		
		do {
			n = input.nextInt();
			if (n == 0){
				break;
			}
			count = 0;
			while (n != 1){
				if (n % 2 == 0){
					n /= 2;
				}
				else {
					n = n * 3 + 1;
				}
				count++;
			}
			System.out.println(count);
		}while (n == 1);
	}
}

Measured memory_bytes: 26228
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;

typedef long long ll;
const int maxn = 1e5 + 7;

vector<int> G[maxn];

int C[maxn];

ll B,N,S;
bool ok;

int dfs(int x) {
	int sz = 1;

	for (int j = 0; j < G[x].size(); j++) {
		int z = G[x][j];
		if (C[z] >= 0) {
			if (C[z] == C[x]) ok = false;
		} else {
			C[z] = 1 - C[x];
			sz += dfs(z);
		}
	}

	return sz;
}


int main() {
	int n,m; scanf("%d %d",&n,&m); B = N = S = 0;

	fill(C, C+maxn, -1);
	fill(G, G+maxn, *new vector<int>());

	for (int i = 0; i < m; i++) {
		int x,y; scanf("%d %d",&x, &y);
		G[x].pb(y); G[y].pb(x);
	}

	for (int i = 1; i <= n; i++) {
		if (C[i] >= 0) continue;
		
		C[i] = 0;

		//cout<<" ;; "<<i<<endl;

		ok = true;
		int sz = dfs(i);

		//cout<<"sz :"<<sz<<endl;

		if (sz == 1) S++;
		else if (ok) B++;
		else N++;
	}

	//cout<<"B = "<<B<<" , N = " <<N<<

	//ll N = n;

	//cout<<B<<" , "<<N<<" , "<<S<<endl;

	ll ans = S * (n - S) * 2 + S * S; // single nodes
	ans += N + B + B; // self pairs

	ans += B * N * 2 + N * (N-1);	// with nonbipartites, different components
	
	ans += B * (B - 1) * 2;  // between bipartites

	printf("%lld\n",ans);
}


Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
int  main(){
    int n;
    cin>>n;
    vector<pair<int,int>>adj[n+2];
    vector<int>colour(n+2);
    vector<int>visit(n+2,0);
    vector<int>degree(n+2,0);
    int m=-1;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        adj[a].push_back(make_pair(b,i));
        adj[b].push_back((make_pair(a,i)));
        degree[a]++;
        degree[b]++;
        m=max(m,degree[a]);
        m=max(m,degree[b]);
    }
    cout<<m<<endl;
    queue<pair<int,int>>q;
    q.push(make_pair(1,-1));
    while(!q.empty()){
       pair<int,int>l =q.front();
       int c=l.second;
       q.pop();
       for(auto node:adj[l.first]){
           if(!visit[node.second]){
               colour[node.second]=++c%m;
               q.push(make_pair(node.first,colour[node.second]));
               visit[node.second]=1;
           }
       }
    }
    for(int i=0;i<n-1;i++)
    cout<<colour[i]+1<<endl;
return 0;
}

Measured memory_bytes: 7808
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long int
#define MOD 1000000007
#define oo 1000000000000000000
#define forr(i,n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define pb push_back
#define vect(x) vector<x>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
using namespace __gnu_pbds; 
using namespace std;

ll valueOfIndex(ordered_set&s , ll i){ return *(s.find_by_order(i)); }
ll indexOfValue(ordered_set&s , ll x){ return s.order_of_key(x); }

ll add(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a+b + p)%p;}
ll mul(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a*b + p)%p;}

ll power(ll x,ll n,ll p=MOD){ if(x==0) return 0; if(n==0 || x==1) return 1LL;
    ll r = (power(x,n/2,p))%p; if(n&1) return mul(mul(r,r,p) , x,p); else return mul(r,r,p);
}

ll a[410];
ll n;

ll dp[410][410];
ll sum[410];
ll gsum(ll s, ll e)
{
    if(s==0) return sum[e];
    else return sum[e]-sum[s-1];
}
void pre()
{
    sum[0]=a[0];
    for(ll i=1;i<n;i++) sum[i] = a[i] + sum[i-1];
    return;
}

ll get(ll s, ll e)
{
    if(s+1>e) return 0;
    if(s+1==e) return a[s]+a[e];
    
    if(dp[s][e]!=-1) return dp[s][e];
    
    ll ans = oo;
    for(ll j=s;j<e;j++)
    {
        ans = min( ans , gsum(s,e) + get( s , j ) + get(j+1,e));
    }
    return dp[s][e] = ans;
}

void solve()
{
    cin >> n;
    forr(i,n) cin >> a[i];
    memset(dp,-1,sizeof(dp));
    pre();
    cout << get( 0 , n-1 );
    
    
    
    return;
}


int main()
{
  
    fastio
    
    ll tc=1;
  //  read(tc);
    while(tc--)
    {
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 1664
fun main() {
    val s = readLine()!!
    var count = 0
    if (s.isNotBlank()) {
        if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') count = 3
        else if (s[0] == 'R' && s[1] == 'R') count = 2
        else if (s[1] == 'R' && s[2] == 'R') count = 2
        else if (s.contains('R')) count = 1
    }
    println(count)
}

Measured memory_bytes: 35920
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s, p;
	cin >> s >> p;
	for (int i = 0; i < s.length(); i++) {
		if (i <= s.length() - p.length()) {
			if (s.substr(i, p.length()) == p) {
				cout << "Yes" << endl;
				return 0;
			}
		}
		else {
			string x = s.substr(i) + s.substr(0, (p.length() - s.length() + i));
			if (x == p) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}


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

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

int main() {
    int N,M,K,t,r=0;
    cin >> N >> M;
    vector<int> A(M,0);

    rep(i,N) {
        cin >> K;
        rep(j,K) {
            cin >> t;
            A.at(t-1)++;
        }
    }

    rep(i,M)    
        if(A.at(i) == N)
            r++;
    cout << r << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int aa(long long int a){
  int ans = 0;
  while(a % 2 < 1){
    a /= 2;
    ans++;
  }
  return ans;
}

int main(){
  int n,ans = 1000;
  scanf("%d",&n);
  long long int a;
  for(int i = 0;i < n;i++){
    scanf("%lld",&a);
    if(ans > aa(a)){
      ans = aa(a);
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
    sc.Split(bufio.ScanWords)
    l := float64(nextInt())
    fmt.Println(math.Pow((l/3.0),3))
}




//===========================
//
// Library
//
//===========================

func max(a, b int) int {
    if a > b {
        return a
    }
    return b
}

func min(a, b int) int {
    if a < b {
        return a
    }
    return b
}

func gcd(x, y int) int {
    if y == 0 {
        return x
    }

    return gcd(y, x%y)
}

//====================
//  var q Queue
//  q.Enqueue(n)
//  n := q.Dequeue()
//====================
type Queue struct {
    data []int
}

func (q *Queue) Enqueue(n int) {
    q.data = append(q.data, n)
}

func (q *Queue) Dequeue() int {
    tmp := q.data[0]
    q.data = q.data[1:]
    return tmp
}

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

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

func nextIntArr(n int) []int {
    var a []int
    for i := 0; i < n; i++ {
        a = append(a, nextInt())
    }
    return a
}

// 数値を桁区切りのスライスにする
func digit(n int, list []int) []int {
   if n > 0 {
       return digit(n/10, append(list, n%10))
   }
   return list
}

func sortIntsRev(list []int) {
    sort.Sort(sort.Reverse(sort.IntSlice(list)))
}

func strReverse(s string) string {
    runes := []rune(s)
    for i := 0; i < len(s)/2; i++ {
        runes[i], runes[len(s)-1-i] = runes[len(s)-1-i], runes[i]
    }
    return string(runes)
}



Measured memory_bytes: 640
//#pragma GCC optimize(2)
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma comment(linker, "/STACK:102400000,102400000")

#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i, beg, end) for (int i = (beg); i < (end); i++)
#define rrep(i, beg, end) for (int i = (beg); i >= (end); i--)
#define sp(i) setprecision(i) << fixed
typedef long long ll;
typedef pair<int, int> P;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
const int N = 200010;
ull p_hash(ull x, ull y) { return (x + y) * (x + y + 1) / 2 + y; } //NxN->N
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

vector<int> l(12), r(12);
int cnt[N];
ll sum[N];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;

    for (int i = 1; i <= k; i++)
        cin >> l[i] >> r[i];

    cnt[1] = 1;
    sum[1] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            int a = l[j], b = r[j];
            if (i - a < 1)
                continue;
            cnt[i] = (cnt[i] + sum[i - a] - sum[max(i - b, 1) - 1]) % mod;
        }
        sum[i] = (sum[i - 1] + cnt[i]) % mod;
    }
    cout << (cnt[n] + mod) % mod << endl;
    return 0;
}

Measured memory_bytes: 5956
N = int(input())
ans = 0
max10 = 100
flg = True
for _ in range(N):
    s = int(input())
    ans += s
    if s % 10 != 0 and max10 > s:
        max10 = s
        flg = False


if flg:
    ans = 0
elif ans % 10 == 0 :
    ans = ans - max10

print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
char charin() {char c; cin>>c; return c;}
string strin() {string s; cin>>s; return s;}
ll mod=1000000007;
int main(){
    ll n=in(),k=in();
    vec a(n);
    rep(i,n){
        a[i]=in();
    }
    ll ans=0;
    ll x=(k*(k+1)/2+mod)%mod;
    ll y=k*(k-1)/2%mod;
    rep(i,n)for(int j=i+1;j<n;j++){
        if(a[i]>a[j]){
            ans+=x;
        }else if(a[i]<a[j]){
            ans+=y;
        }
        ans%=mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n, i, count = 0;
    scanf("%d",&n);
    int a[n + 1], b[n + 1], c[n + 1];
    for(i = 1; i <= n; i++)
        scanf("%d",&a[i]);
    for(i = n; i > 0; i--){
        int sum = a[i];
        for(int j = i * 2; j <= n; j += i)
            sum += b[j];
        if(b[i] = sum % 2) 
            c[count++] = i;
    }
    printf("%d\n",count);
    while(count--)
        printf("%d ",c[count]);
    return 0;
}

Measured memory_bytes: 3072
#define ll long long
#include <iostream>
using namespace std;
int main()
{
    ll answer=0,n,D,x,y;
    std::cin >> n>>D;
    for(ll i=0;i<n;i++){
        std::cin >> x>>y;
        if(x*x+y*y<=D*D)
            answer++;
    }
    std::cout << answer << std::endl;
    return 0;
}

Measured memory_bytes: 3108
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define REP(i, k) for (decltype(k) i=0; i<k; i++)
#define LOOP(k) REP(ngtkana_is_a_geneus, k)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

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

    usize n, q;
    std::cin >> n >> q;
    vec<usize> a(n), ckd(n), mul(n);
    usize ans = n;
    REP (i, n) {
        usize x; std::cin >> x, x--;
        a.at(i) = x;
        ckd.at(x)++;
        if (ckd.at(x) <= x + 1) {
            if (0 == mul.at(x + 1 - ckd.at(x))++) ans--;
        }
    }

    while (q--) {
        usize i, y; std::cin >> i >> y, i--, y--;
        usize x = a.at(i);
        ckd.at(x)--;
        if (ckd.at(x) <= x) {
            if (--mul.at(x - ckd.at(x))==0) ans++;
        }
        if (ckd.at(y) <= y) {
            if (mul.at(y - ckd.at(y))++==0) ans--;
        }
        ckd.at(y)++;
        a.at(i) = y;
        std::cout << ans << '\n';
    }
}


Measured memory_bytes: 7552
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    char[] s,t;

    private void solve() {
        s = next().toCharArray();
        t = next().toCharArray();

        int L = s.length;
        for(int i = 0;i < L;i++) {
            boolean ok = true;
            for(int j = 0;j < L;j++) {
                int k = (i + j) % L;

                if (s[k] != t[j]) {
                    ok = false;
                    break;
                }
            }

            if (ok) {
                out.println("Yes");
                return;
            }
        }
        out.println("No");
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

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

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

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

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

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

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

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


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define emb emplace_back
#define fcout cout << fixed << setprecision(15)

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

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

vector<ll> a;

void newlun(ll v){
  if(v % 10 == 1) {
    a.emb(v*10);
    a.emb(v*10+1);
    a.emb(v*10+2);
  } else if(v % 10 == 2) {
    a.emb(v*10+1);
    a.emb(v*10+2);
    a.emb(v*10+3);
  } else if(v % 10 == 3) {
    a.emb(v*10+2);
    a.emb(v*10+3);
    a.emb(v*10+4);
  } else if(v % 10 == 4) {
    a.emb(v*10+3);
    a.emb(v*10+4);
    a.emb(v*10+5);
  } else if(v % 10 == 5) {
    a.emb(v*10+4);
    a.emb(v*10+5);
    a.emb(v*10+6);
  } else if(v % 10 == 6) {
    a.emb(v*10+5);
    a.emb(v*10+6);
    a.emb(v*10+7);
  } else if(v % 10 == 7) {
    a.emb(v*10+6);
    a.emb(v*10+7);
    a.emb(v*10+8);
  } else if(v % 10 == 8) {
    a.emb(v*10+7);
    a.emb(v*10+8);
    a.emb(v*10+9);
  } else if(v % 10 == 9) {
    a.emb(v*10+8);
    a.emb(v*10+9);
  } else if(v % 10 == 0) {
    a.emb(v*10);
    a.emb(v*10+1);
  }
}

int main() {
  int k;
  cin >> k;
  for(int i = 1;i<=9;i++) {
    a.emb(i);
    if(i==k) {
      cout << k << endl;
      return 0;
    }
  }

  int num = 9;
  while(1) {
    vector<ll> old;
    swap(a,old);
    for(auto v : old) {
      newlun(v);
    }
    if(num + a.size() >= k) break;
    num += a.size();
  }

  cout << a.at(k - num - 1) << endl;


  return 0;
}


Measured memory_bytes: 1712
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.sqrt

fun main(args: Array<String>) {

    // IO Templates
    val br = BufferedReader(InputStreamReader(System.`in`))
    val out = PrintWriter(System.out)

    val s = br.readLine()!!

    out.println(s + if (s.last() == 's') "es" else "s")

    out.flush()
}

Measured memory_bytes: 35672
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 100000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back




template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;



template< typename T >
vector<T> dijkstra(WG<T> &g,int s){
  const auto lim = numeric_limits<T>::max();
  vector<T> dist(g.size(),lim);
  using Pi = pair<T,int>;
  priority_queue<Pi,vector<Pi>,greater<Pi>> q;
  dist[s] = 0;
  q.emplace(dist[s],s);
  while(!q.empty()){
    T cost;
    int idx;
    tie(cost,idx) = q.top();
    q.pop();
    if(dist[idx] < cost) continue;
    for( auto &e : g[idx]){
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      q.emplace(dist[e.to],e.to);
    }
  }
  return dist;
}



int main(){
  int h,w;
  cin>>h>>w;
  WG<int> es(10);

  rep(i,10){
    rep(j,10){
      int c;
      cin>>c;
      es[i].PB(edge<int>(j,c));
    }
  }
  vector<vector<int>> v(10);

  rep(i,10){
    v[i] = dijkstra(es,i);
  }

  int ans=0;
  rep(i,h){
    rep(j,w){
      int a;
      cin>>a;
      if(a==-1) continue;
      ans+=v[a][1];
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
int N;
const int MAX_N = 100010;
int a[MAX_N];
int cnt[3];

int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&a[i]);
		if(a[i]%4==0)cnt[2]++;
		else if(a[i]%2==0)cnt[1]++;
		else cnt[0]++;
	}

	if(cnt[0]==cnt[2]+1 && cnt[1]==0){
		puts("Yes");
	}else if(cnt[0] > cnt[2]){
		puts("No");
	}else{
		puts("Yes");
	}

	return 0;
}

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

typedef long long ll;
const int mx = 2e5 + 5;

ll S[mx];
int n;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> S[i];
        S[i] += S[i-1];
    }
    int c1=0, c2 = 1, c3 = 1;
    ll ans = LLONG_MAX;
    for(ll p, q, r, s, pp, qq, rr, ss;c2 <= n; c2++){
        while(c1 < c2){
            p = S[c1]; q = S[c2] - S[c1];
            pp = S[c1+1]; qq = S[c2] - S[c1+1];
            if(abs(p-q) > abs(pp-qq)) ++c1;
            else break;
        }
        c3 = max(c2, c3);
        while(c3 < n){
            r = S[c3] - S[c2]; s = S[n] - S[c3];
            rr = S[c3+1] - S[c2]; ss = S[n] - S[c3+1];
            if(abs(r-s) > abs(rr - ss)) ++c3;
            else break;
        }
        ans = min(ans, max({p,q,r,s}) - min({p,q,r,s}));
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1792
#include <stdio.h>


int main() {
  int n,sum,x,i,j;

  while(1) {
    sum = 0;
    scanf("%d",&n);

    if(n == 0) break;

    for(i = 1; i*i<n;i++) {
      if(n%i == 0) {
	sum = sum + i;
	if(i*i != n) sum =sum + n / i;
      }

    } 

    sum -= n;
    
    
    if(sum == n) printf("perfect number\n");
    else if(n > sum) printf("deficient number\n");
    else printf("abundant number\n");

  }

  return 0;

}

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;


int main()
{
int A,B;
cin>>A;
cin>>B;
int a=B%A;
if(a==0){cout<<A+B<<endl;}else{cout<<B-A<<endl;}
/*for(int i=0;i<10;i++){

}*/

return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll mod_pow(ll a, ll b) {
	if (b == 0) return 1;
	if (b % 2 == 0) {
		ll x = mod_pow(a, b / 2);
		return (x*x) % MOD;
	}
	return (a*mod_pow(a, b - 1)) % MOD;
}
int a[300][300];
int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> a[i][j];
		}
	}
	int r = 0;
	for (int i = 0; i < N; i++) {
		int idx = -1, l = -1;
		for (int j = i; j < N; j++) {
			int k;
			for (k = 0; k < M; k++) {
				if (a[j][k]) break;
			}
			if (k < M) {
				if (idx == -1 || l > k) idx = j, l = k;
			}
		}
		if (idx == -1) break;
		r++;
		for (int j = 0; j < M; j++) {
			swap(a[i][j], a[idx][j]);
		}
		for (int j = 0; j < N; j++) {
			if (i == j || a[j][l] == 0) continue;
			for (int k = 0; k < M; k++) {
				a[j][k] ^= a[i][k];
			}
		}
	}
	ll ans = mod_pow(2, N + M - 1);
	(ans += MOD - mod_pow(2, N + M - r - 1)) %= MOD;
	cout << ans << endl;
}

Measured memory_bytes: 640
n = gets.to_i
ary = gets.split().map(&:to_i)
ary2 = []
num = 1
max = 0
ary.each do |a|
  if a == num
    ary2 << a
    num += 1
    max = num
  end
end
if max == 0
  puts -1
else
  puts n - ary2.length
end

Measured memory_bytes: 16956
#include<stdio.h>

int binarySearch(int *, int);

int n;

int main(void){

  int q,s[100000],t,count=0,i;


  scanf("%d",&n);
  for(i = 0 ; i < n ; i++)
    scanf("%d",&s[i]);


  scanf("%d",&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d",&t);

    if(binarySearch(s,t)==1) count++;

  }

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

  return 0;

}


int binarySearch(int *s, int key){

  int i,left,right,mid;

  left = 0;
  right = n;

  while(left < right){

    mid = (left + right)/2;
      
    if(key == s[mid]) return 1;

    if(key > s[mid]) left = mid + 1;
    else if(key < s[mid]) right = mid;
    
  } 
  
  return 0;

}

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

int main() {
  string S;
  cin >> S;
  vector<int> count(2, 0);
  for (int i = 0; i < S.size(); i++) {
    count.at(int(S.at(i)) - int('0'))++;
  }
  cout << min(count.at(0), count.at(1)) * 2 << endl;
}

Measured memory_bytes: 512
#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++)
#define all(v) v.begin(), v.end()

int main() {
  int N; cin >>N;
  vector<int>a(N+1);
  for(int i=1;i<=N;i++){
    cin>>a.at(i);
  }
  int kotae=a.at(1);
  if(kotae==2){
    cout<<1<<endl;
    return 0;
  }
  int x=1;
  int count=1;
  while(x!=2){
    kotae=a.at(kotae);
    count++;
    if(kotae==2){
      cout<<count<<endl;
      return 0;
    }
    if(count>N+1){
      cout<<-1<<endl;
      return 0;
    }
  }
}

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

using namespace std;

typedef long long ll;

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


namespace Knap1
{
	int N, W;
	int ws[101];
	int vs[101];
	ll dp[101][100001];

	void solve()
	{
		cin >> N >> W;
		for (int i = 1; i <= N; ++i) {
			cin >> ws[i] >> vs[i];
		}

		memset(dp, 0, sizeof(dp));
		//i番目までから選んだ最大の価値を求める
		for (int i = 1; i <= N; ++i) {
			//重さw以下までの選び方全てを記録する
			for (int w = 0; w <= W; ++w) {
				if (ws[i] <= w) {
					//i番目を選ぶ場合と選ばない場合で、価値の高い方を選択する
					dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - ws[i]] + vs[i]);
				}
				else {
					dp[i][w] = dp[i - 1][w];
				}
			}
		}
		cout << dp[N][W] << endl;
	}
}
int main()
{
	Knap1::solve();
}


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

int main() {
  int P, Q, R;
  cin >> P >> Q >> R;
  
  vector<int> vec;
  vec = {P, Q, R};
  
  sort(vec.begin(), vec.end());
  
cout << vec.at(0) + vec.at(1) << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,m,c,ans=0,sum=0;
    cin >> n >> m >> c;
    ll a[n][m];
    ll b[m];
    for(ll i=0;i<m;i++)
    {
        cin >> b[i];
    }
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<m;j++)
        {
            cin >> a[i][j];
        }
    }
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<m;j++)
        {
            sum = a[i][j]*b[j] + sum;
        }
        if(sum +c>0)
        {
            ans++;
        }
        sum = 0;
    }
    cout << ans << endl;
}


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

int main(void){
  int N, M;
  cin >> N >> M;
  int q[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  vector<int> use;
  for(int i=0; i<M; i++){
    int a;
    cin >> a;
    use.push_back(a);
  }
  sort(use.begin(), use.end());
  string dp[N+1];
  for(int i=0; i<N+1; i++) dp[i] = "-1";
  dp[0] = "";
  for(int i=0; i<N; i++){
    bool contflag = false;
    for(int j: use){
      if(i+q[j] > N) continue;
      contflag = true;
      if(dp[i] == "-1") continue;
//      cout << i << ", " << j << ", " << dp[i] << endl;
      
      string tmp;
      if(dp[i] >= to_string(j)) tmp = dp[i] + to_string(j);
      else tmp = to_string(j) + dp[i];
      
      if(dp[i+q[j]] != "-1" && dp[i+q[j]].size() > tmp.size()) continue;
      else if(dp[i+q[j]].size() < tmp.size()) dp[i+q[j]] = tmp;
      else {
        dp[i+q[j]] = (dp[i+q[j]] >= tmp) ? dp[i+q[j]] : tmp;
      }
//      cout << i << ", " << j << ", " << dp[i+q[j]] << endl;
    }
    if(!contflag) break;
  }
  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 32384
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<algorithm>

using namespace std;

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

long double N, K;

int main() {
	cin >> N >> K;
	long double ans = 0.0;
	long double coin = N;
	if (N >= K) {//コインなし
		ans += (N - K + 1.0) / N;
		coin = K - 1.0;
	}
	for (long double i = 1; i <= coin; i++) {
		long double num = i;
		long double c_num = 1.0 / N;
		while (num < K) {
			num *= 2.0;
			c_num *= 0.5;
		}
		//cout << "c_num = " << c_num << endl;
		ans += c_num;
	}
	cout << setprecision(16) << ans << endl;
}

Measured memory_bytes: 256