akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    ll a, b;
    cin >> a >> b;
    vll v;
    if (b - a < 10) {
        for (ll i = a; i <= b; ++i) {
            v.push_back(i);
        }
    }
    else {
        for (ll i = a; i < ((a + 3) / 4) * 4; ++i) {
            v.push_back(i);
        }
        for (ll i = (b / 4) * 4; i <= b; ++i) {
            v.push_back(i);
        }
    }

    ll ans = 0;
    for (int i = 0; i < v.size(); ++i) {
        ans ^= v[i];
    }
    cout << ans << endl;
    
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
def main():
  m, n = map(int, input().split())
  
  if n <= 1:
    ans1 = 0
  else:
    ans1 = n * (n-1) / 2
    
  if m <= 1:
    ans2 = 0
  else:
    ans2 = m * (m-1) / 2
    
  print(int(ans1 + ans2))
  
main()

Measured memory_bytes: 9080
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, i;
    cin>>n;
    int arr[n], dp[n];
    for(i = 0; i < n; i++)
    {
        dp[i] = INT_MAX;
        cin>>arr[i];
    }
    dp[0] = 0;
    for(i = 1; i < n; i++)
    {
        dp[i] = min(dp[i], dp[i-1] + abs(arr[i] - arr[i-1]));
        if(i > 1)
           dp[i] = min(dp[i], dp[i-2] + abs(arr[i] - arr[i-2]));
    }
    cout<<dp[n-1];
return 0;
}
  

Measured memory_bytes: 1024
n, m, k = gets.split.map(&:to_i)

as = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)

cs = [0]
c = 0
as.each do |a|
  c += a
  cs << c
end

ds = [0]
d = 0
bs.each do |b|
  d += b
  ds << d
end

mx = 0
(n+1).times do |i|
  # read (i+1) books from desk A
  if cs[i] > k
    next
  end
  rest = k - cs[i]

  l = 0
  r = m

  while r - l > 0
    mid = (l + r + 1) / 2

    if ds[mid] <= rest
      l = mid
    else
      r = mid - 1
    end
  end

  if i + l > mx
    mx = i + l
  end
end

p mx


Measured memory_bytes: 45084
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<bool>> graph(n+1,vector<bool>(n+1));
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    graph[a][b] = true;
    graph[b][a] = true;
  }

  vector<int> order(n);
  for(int i=0;i<n;i++) order[i] = i+1;

  ll cnt = 0;

  do{
    if(order[0] != 1) continue;

    for(int i=0;i<n-1;i++){
      if(!graph[order[i]][order[i+1]] && !graph[order[i+1]][order[i]]){
        break;
      }
      if(i == n-2){
        cnt++;
      }
    }
  }while(next_permutation(order.begin(),order.end()));

  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  string s;
  int x;
  cin>>s>>x;
  for(int i=0;i<sz(s);i+=x)
    {
      cout<<s[i];
    }
  cout<<endl;
  return 0 ;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <cassert>
#include <functional>
#include <iterator>
using namespace std;
using VI = vector<int>;

bool check(string s) {
    if (s.size() % 2) return 0;
    string a = "", b = "";
    for (int i = 0; i < s.size() / 2; i++) {
        a += s[i];
    }
    for (int i = s.size() / 2; i < s.size(); i++) {
        b += s[i];
    }
    return a == b;
}

int main() {
    string s;
    cin >> s;
    for (int i = s.size() - 1; i >= 2; i--) {
        if (check(s.substr(0, i))) {
//            cout << s.substr(0, i) << endl;
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
import math
max = 1000000007
def test(x):
  return x if x<max else (x % max)

def kai(m):
  if m == 1:
    return 1
  else:
    return test(kai(m-1) * m)

n,m = map(int,input().split())
ret = 0
if n == m:
  k = math.factorial(m)
  ret = test(2 * k * k)
elif n-m == 1:
  k = math.factorial(m)
  ret = test(k * k * n)
elif n-m == -1:
  k = math.factorial(n)
  ret = test(k * k * m)
print(ret)

Measured memory_bytes: 5184
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
vector<int> c;
struct graph {
  int n;
  int idx = 0;
  vector<vector<int>> g;
  vector<int> val;
  graph(){};
  graph(int _n) {
    n = _n;
    g.resize(n);
    val.resize(n);
  };
  void add_edge(int a, int b) {
    g[a].push_back(b);
    g[b].push_back(a);
  }
  void dfs(int cur, int pre) {
    val[cur] = c[idx];
    idx++;

    for (auto&& u : g[cur]) {
      if (u != pre) {
        dfs(u, cur);
      }
    }
  }
};

signed main() {
  int n;
  cin >> n;
  graph gr(n);
  rep(i, n - 1) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    gr.add_edge(x, y);
  }
  c.resize(n);
  for (auto&& u : c) cin >> u;
  sort(begin(c), end(c), greater<int>());
  gr.val[0] = c[0];
  gr.dfs(0, -1);
  int tmp = 0;
  for (int i = 1; i < n; i++) tmp += c[i];
  cout << tmp << endl;
  for (auto&& u : gr.val) cout << u << ((&u < &gr.val.back()) ? " " : "\n");
}

Measured memory_bytes: 1280
#include<iostream>
using namespace std;
int main(){
  long long int x, y;
  cin>>x>>y;
  if(y&1) cout<<"No"<<endl;
  else{
    int l = x*2;
    int r = x*4;
    if(l<=y && y<=r){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }

}


Measured memory_bytes: 3628
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// }}}

ll a, b, c, d;

ll roundup(ll x, ll b)
{
    return ((x+b-1) / b) * b;
}

ll rounddown(ll x, ll b)
{
    return (x / b) * b;
}

ll gcd(ll a, ll b)
{
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcd(b, a % b);
}

inline ll lcm(ll a, ll b)
{
    // a*b may be overflowed
    return a / gcd(a, b) * b;
}
void solve()
{
    ll lcm_cd = lcm(c, d);

    ll cu = roundup(a, c);
    ll cd = rounddown(b, c);
    ll ncu = cu / c;
    ll ncd = cd / c;

    ll du = roundup(a, d);
    ll dd = rounddown(b, d);
    ll ndu = du / d;
    ll ndd = dd / d;

    ll lu = roundup(a, lcm_cd);
    ll ld = rounddown(b, lcm_cd);
    ll nlu = lu / lcm_cd;
    ll nld = ld / lcm_cd;

#if 0
    cout << cu << " " << cd << " " << ncu << " " << ncd << endl
         << du << " " << dd << " " << ndu << " " << ndd << endl
         << lu << " " << ld << " " << nlu << " " << nld << endl;

    cout << (ncd - ncu + 1) << " "
         << (ndd - ndu + 1) << " "
         << (nld - nlu + 1) << endl;
#endif

    cout << (b - a + 1) - ((ncd - ncu + 1) + (ndd - ndu + 1) - (nld - nlu + 1)) << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b >> c >> d;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
def main():
    s = input()
    k = int(input())
    lst = set()
    l = len(s)
    for i in range(l):
        for j in range(i, i + k):
            lst.add(s[i:j+1])
    lst = list(lst)
    lst.sort()
    print(lst[k - 1])
main()

Measured memory_bytes: 69208
#include <cstdio>
#include <utility>
#include <vector>
#include <queue>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in(gcu());}
_sc(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for (char c: s) pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	vector<priority_queue<int>> v(in());
	for (int q = in(); q; q--) {
		int o = in();
		auto &t = v[in()];
		switch(o) {
		case 0:
			t.push(in());
			break;
		case 1:
			if (!t.empty())
				outl(t.top());
			break;
		default:
			if (!t.empty())
				t.pop();
		}
	}
}


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

def solve(A):
    ans = 0
    leaves = sum(A)
    prev_node_capacity = 1

    for ai in A:
        if ai > prev_node_capacity:
            return -1
        ans += min(prev_node_capacity, leaves)

        leaves -= ai
        prev_node_capacity -= ai
        prev_node_capacity *= 2

    return ans
  
print(solve(A))

Measured memory_bytes: 20060
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count  = 0
for i in range(n):
    if(b[i] <= a[i]):
        a[i] -= b[i]
        count += b[i]
    else:
        sub = b[i] - a[i]
        if sub < a[i + 1]:
            a[i + 1] -= sub
            count += (a[i] + sub)
            a[i] = 0
        else:
            count += a[i] + a[i + 1]
            a[i + 1] = 0
            a[i] = 0
print(count)

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

int main() {
  int N,Rcnt=0,Bcnt=0;
  string S;

  cin >> N;
  cin >> S;

  for(int i =0;i <N;i++){
    if(S.at(i) == 'R'){
      Rcnt +=1;
    }
    else if(S.at(i) == 'B'){
      Bcnt +=1;
    }
  }
  if(Rcnt > Bcnt){
    cout  << "Yes" <<endl;
  }
  else{
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 256
import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    A = [None] + input_int_list()
    ans = 0
    d = defaultdict(int)
    # i < j とすると、
    # j - i = Ai + Aj
    # Ai + i = j - Aj となる
    # 列の後ろから評価し、条件を満たす個数を足していけば良い
    # 計算量：O(n)
    for i in range(n, 0, -1):
        cur = i + A[i]
        ans += d[cur]
        d[i - A[i]] += 1
    print(ans)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 153168
#include<stdio.h>

int main(void){
  int A,B;
  int result;
  scanf("%d%d",&A,&B);
  result = A * B;
  if(result < A + B)
    result = A + B;
  if(result < A - B)
    result = A - B;
  printf("%d",result);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(void)
{
	long int a,b,i=1,j=1;
	cin>>a>>b;
	while(1){
		if(a*i==b*j){
			cout<<a*i<<endl;
			break;
		}
		if(a*i<b*j) i++;
		else j++;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;

int N, M;
bool f[200005];
vector<int> v;

int main() {
  scanf("%d %d", &N, &M);
  rep(i, 0, M) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (a == 1) v.pb(b);
    if (b == N) f[a] = true;
  }
  
  for (int i = 0; i < (int)v.size(); i++) {
    if (f[v[i]]) {
      puts("POSSIBLE");
      return 0;
    }
  }
  
  puts("IMPOSSIBLE");
  return 0;

}

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

int main()
{

int n,X,T;
cin>>n>>X>>T;

int totalTime=0;
int sumMat=0;

while(sumMat!=n)
{

    totalTime=totalTime+T;
  sumMat=sumMat+X;
    if(sumMat>n)
    {
        break;
    }
    
    

}

cout<<totalTime<<endl;

    return 0;
}


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

int main(int argc, char *argv[]) {
	int N = 0;
	int K = 0;
	std::cin >> N >> K;

	int answer = 0;
	if (N > K) {
		answer = (N % K == 0) ? 0 : 1;
	}
	if (N == K) {
		answer = 0;	
	}
	if (N < K) {
		answer = 1;	
	}

	std::cout << answer << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define JDZ(a,b) (abs(a))+(abs(b))
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	int t,x,y,ct=0,cx=0,cy=0;
	for(register int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&t,&x,&y);
		if(((JDZ((x-cx),(y-cy)))>(t-ct))||(((JDZ((x-cx),(y-cy)))%2)-((t-ct)%2)))
		{
			printf("No");
			goto endreturn;
		}
		ct=t,cx=x,cy=y;
	}
	printf("Yes");
	endreturn:
		putchar(10);
		return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890123
typedef pair<ll, ll> P;



//initialization here
//
const int maxn = 1e5+10;

//
//initialization finish


// your function is here
//

//
// your function finished



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here
	//
	int n, a; cin >> n >> a;

	if (n % 500 <= a) Yes;
	else No;

	//
	// your code finished


	return 0;
}

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

int N;
pair<double,double> A,B,C;
const double EPS = 1e-6,INF = 1e9;

double dist(pair<double,double> a,pair<double,double> b)
{
	double x = a.first - b.first,y = a.second - b.second;
	return sqrt(x * x + y * y);
}

int main()
{
	scanf("%d",&N);
	FOR(i,0,N){
		scanf("%lf%lf%lf%lf%lf%lf",&A.first,&A.second,&B.first,&B.second,&C.first,&C.second);
		pair<double,double> x((A.first + B.first) / 2.0,(A.second + B.second) / 2.0);
		pair<double,double> y((A.first + C.first) / 2.0,(A.second + C.second) / 2.0);
		pair<double,double> ans(INF,INF);
		double p = INF,q = INF,r = INF,s = INF;
		if(abs(A.second - B.second) < EPS){
			ans.first = x.first;
		}
		else{
			p = - (A.first - B.first) / (A.second - B.second);
			q = x.second - x.first * p;
		}
		if(abs(A.second - C.second) < EPS){
			ans.first = y.first;
		}
		else{
			r = - (A.first - C.first) / (A.second - C.second);
			s = y.second - y.first * r;
		}
		assert(p != r);
		if(ans.first == INF){
			ans.first = (s - q) / (p - r);
		}
		if(p != INF){
			ans.second = p * ans.first + q;
		}
		else{
			ans.second = r * ans.first + s;
		}
		printf("%.3f %.3f %.3f\n",ans.first,ans.second,dist(A,ans));
	}

	return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <queue>
#include <set>
using namespace std;

class Info{
public:
	string s;
	int depth;
};

bool is_answer(string s){
	for(int i=1;i<s.length();i++){
		if(s.at(0) != s.at(i)) return false;
	}
	return true;
}

string change_color(string s, int i){
	char f = s.at(i);
	char b = s.at(i+1);

	if(f == 'r' && b == 'g' || f == 'g' && b == 'r'){
		s.replace(i,2,"bb");
	}
	else if(f == 'r' && b == 'b' || f == 'b' && b == 'r'){
		s.replace(i,2,"gg");
	}
	else if(f == 'g' && b == 'b' || f == 'b' && b == 'g'){
		s.replace(i,2,"rr");
	}

	return s;
}

int bfs(string s){
	int len = s.length();
	set<string> worm_set;
	queue<Info> q;
	Info tmp = {s,0};

	if(is_answer(s)){
		return 0;
	}

	q.push(tmp);
	worm_set.insert(s);

	while(!q.empty()){
		tmp = q.front(); q.pop();

		for(int i=0;i<len-1;i++){
			string next_worm = change_color(tmp.s,i);

			if(is_answer(next_worm)){
				return tmp.depth + 1;
			}

			if(next_worm != tmp.s &&
				 worm_set.find(next_worm) == worm_set.end()){
				Info next_info = {next_worm, tmp.depth + 1};

				q.push(next_info);
				worm_set.insert(next_worm);
			}
		}
	}

	return -1;
}

int main(void){
	string s;

	while(cin >> s && s != "0"){
		int ans = bfs(s);

		if(ans >= 0){
			cout << ans << endl;
		}
		else{
			cout << "NA\n";
		}
	}

  return 0;
}

Measured memory_bytes: 1596
def main():
    N = int(input())
    st, sx, sy = 0, 0, 0
    ans = []
    for _ in range(N):
        nt, nx, ny = map(int, input().split())
        if (nx + ny - sx - sy) > (nt - st):
            ans.append(False)
            continue
        if (nx + ny - sx - sy) % 2 != (nt - st) % 2:
            ans.append(False)
            continue
        ans.append(True)
    print('YNeos'[not all(ans)::2])


main()

Measured memory_bytes: 3864
n = gets.chomp.to_i
h_arr = gets.chomp.split(" ").map{|i|i = i.to_i}
#pp n
#pp h_arr

#puts "alksdjf;lakjsf"
max=0
count=0

h_arr.each{|i|
  if(max<=i) then 
    count +=1
    max=i
  end
}

puts count






Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <string>

#define REP(i, n) for (int i=0;i<(n);i++)
#define FOR(i, a, b) for (int i=(a);i<(b);i++)

using namespace std;

int N, Y;

int main()
{
    scanf("%d %d", &N, &Y);
    int a, b, c;
    // 5000*9 = 1000*5+10000*4, 9=5+4より、0<=b<9のみ考えればよい
    // 10000*a + 5000*b + 1000*c = Y
    // a + b + c = N
    // 9000*a + 4000*b = Y - 1000*N
    REP(i, 9) {
        int tmp = Y - 1000*N - 4000*i;
        if (tmp%9000==0) {
            a = tmp / 9000;
            b = i;
            c = N - b - a;
            if (a<0 || c<0) {
                a = -1;
                b = -1;
                c = -1;
            }
            break;
        }
    }
    cout << a << " " << b << " " << c << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int n,used[10]={0},use[10]={0},t=1,sum;
int a[50000]={0};
int dfs(int k,int *a)
{  int i;
    if(k==n)
    {   sum=0;
       for(i=1;i<=n;i++)
         sum=sum*10+used[i];
        // printf("%d\n",sum);
    a[t++]=sum;
   // printf("   %d\n",a[t-1]);
    return 0;}
    for(i=1;i<=n;i++)
    {  if(use[i]==0)
        {   use[i]=1;
            used[k+1]=i;
            dfs(k+1,a);
            use[i]=0;
        }
    }
}
int main()
{  int i,suma=0,sumb=0,x,A=0,B=0;
   scanf("%d",&n);
   dfs(0,a);
 //  for(i=1;i<=6;i++) printf("%d\n",a[i]);
   for(i=1;i<=n;i++)
   {  scanf("%d",&x);
     suma=suma*10+x;
   }
   for(i=1;i<=n;i++)
   {  scanf("%d",&x);
     sumb=sumb*10+x;
   }
   for(i=1;i<=45000;i++)
   {  if(a[i]==suma)suma=i,A=1;
      if(a[i]==sumb)sumb=i,B=1;
      if(A==1&&B==1) break;
   }
   //printf("%d %d\n",suma,sumb);
   printf("%d",abs(suma-sumb));


    return 0;
}

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

#define I inline void 

using namespace std ; 

using ll = long long ; 
using ld = long double ; 

const int N = 2e6 + 7 ; 

// How interesting!

int n; 


int main(){
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ; 
	//freopen("in.in", "r" , stdin) ;
	
	ll ans = 0 ; 
	cin >> n; 
	ll mx = 0 ;
	for(int i = 0 ;i < n;i++){
		ll x ;
		cin >> x ; 
		ans += max(0ll , mx - x) ; 
		mx = max(mx , x) ;
	}
	cout<< ans ; 
	return 0 ; 
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

int main(void)
{
  ll x; cin >> x;
  ll a, b;
  ll ma = 1000;
  vector<ll>a5(ma);
  REP(i, ma) {
    a5[i] = i * i * i * i * i;
    //    cout << i << " " << a5[i] << endl;
  }
  REP(i, ma) {
    REP(j, ma) {
      a = a5[i];
      b = a5[j];
      if(a-b==x) {cout << i << " " << j << endl; return 0;}
      if((-a)-b==x) {cout << (-i) << " " << j << endl;return 0;}
      if(a-(-b)==x) {cout << i << " " << (-j) << endl;return 0;}
      if((-a)-(-b)==x) {cout << (-i) << " " << (-j) << endl;return 0;}
    }
  }
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>

#define INF 1000000000000000000LL
using ll = long long int;
int n;
std::vector<ll> a;
std::vector<ll> b;

ll sum(int from, int until)
{
  return b[until] - b[from];
}

int search(int from, int until)
{
  int l = from; // dummy
  ll tmp = INF;
  for (int i = from + 1; i <= until - 1; i++) {
    ll diff = abs(sum(from, i) - sum(i, until));
    if (diff < tmp) {
      l = i;
      tmp = diff;
    }
  }

  return l;
}

int bs(int from, int until)
{
  int index = from; // dummy
  ll mini = INF;

  int l = from + 1;
  int r = until;

  while (l < r) {
    int mid = l + (r - l) / 2;
    ll det = sum(from, mid) - sum(mid, until);

    if (abs(det) < mini) {
      index = mid;
      mini = abs(det);
    } 

    if (det > 0) { // 前の方が大きい
      r = mid;
    } else if (det < 0) {
      l = mid + 1;
    } else {
      break;
    }
  }

  return index;
}


int main()
{
  using namespace std;

  cin >> n;
  a.reserve(n);
  b.reserve(n+1);

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

  b.push_back(0);
  ll accum = 0;
  for (int i = 0; i < n; i++) {
    accum += a[i];
    b[i+1] = accum;
  }

  ll minimum = INF;
  for (int c = 2; c <= n - 2; c++) {
    int l = bs(0, c);
    int r = bs(c, n);

    ll mn = min(sum(0, l), min(sum(l, c), min(sum(c, r), sum(r, n))));
    ll mx = max(sum(0, l), max(sum(l, c), max(sum(c, r), sum(r, n))));

    minimum = min(minimum, mx - mn);
  }

  cout << minimum << endl;

  return 0;
}

Measured memory_bytes: 3328
s = input()
n = len(s)
ans = 101

for i in range(n):
    move = 0
    r = -1
    for j in range(n):
        if s[j] == s[i]:
            move = max(move, j-r-1)
            r = j

    move = max(move, n-r-1)
    ans = min(ans, move)

print(ans)

Measured memory_bytes: 3064
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <map>
#include <string>
#include <utility>
#include <vector>

int main() {
  size_t n;
  scanf("%zu", &n);

  std::vector<intmax_t> a(n), b(n);
  for (size_t i = 0; i < n; ++i) {
    scanf("%jd %jd", &a[i], &b[i]);
  }

  std::sort(a.begin(), a.end());
  std::sort(b.begin(), b.end());

  intmax_t l0 = a[(n-1)/2], r0 = b[(n-1)/2];
  intmax_t l1 = a[n/2], r1 = b[n/2];

  fprintf(stderr, "[%jd, %jd]\n", l0, r0);
  fprintf(stderr, "[%jd, %jd]\n", l1, r1);

  if (n % 2 == 1) {
    printf("%jd\n", r0-l0+1);
  } else {
    printf("%jd\n", (r1+r0)-(l1+l0)+1);
  }
}


Measured memory_bytes: 5924
#include<bits/stdc++.h>
using namespace std;
int main(){
	
	long long int x,k,d,n,ans;	cin>>x>>k>>d;
	x=fabs(x);
	n=x/d;
	if(n>=k)	ans = x-k*d;
	else{
		x-=n*d;
		k-=n;
		if(k%2==0) ans = fabs(x);
		else ans = min(fabs(x-d),fabs(x+d));

	}

	cout<<ans;
return 0;
}

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

int main()
{
	int n;cin>>n;
	vector<int> b(n);
	for(int i=0;i<n;i++)cin>>b[i];
	int ans=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			ans+=b[i]*b[j];
		}
	}
	cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#define sf(x) scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
#define lli long long int
#define ll64 int64_t
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define frr(i,a) for(int i=0;i<a;i++)
#define frl(i,a) for(lli i=0;i<a;i++)
int main()
{
    lli n;
    double d;
    cin>>n>>d;
    double p,q;
    lli c=0;
    frr(i,n)
    {
        cin>>p>>q;
        double x=sqrt(p*p+q*q);
        if(x<=d)
        {
            c++;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3836
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  string S;
  cin >> S;
  ll ans = 0;
  bool keta = false;
  for(int i=S.size()-1; i>=0; i--){
    int d = S[i] - '0';
    if(keta){
      d++;
      keta = false;
    }
    if(d > 5 || (d==5 && i>0 && S[i-1]-'0'>4)){
      ans += 10-d;
      keta = true;
    }else{
      ans += d;
    }
  }
  if(keta){
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

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

    int n;
    cin >> n;

    if (n%10 == 3)
        cout << "bon\n";
    else if (n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8)
        cout << "pon\n";
    else
        cout <<"hon\n";
}


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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef string str;
typedef vector<char> vc;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define all(a) a.begin(), a.end()

template <typename T>
T Sum(vector<T> n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (accumulate(n.begin() + a, n.end(), 0));
  }
  else
  {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}
template <>
ld Sum(vector<ld> n, ll a, ll b)
{
  if (b == 0)
  {
    return (accumulate(n.begin() + a, n.end(), 0));
  }
  else
  {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}

template <typename T>
void Sort(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (sort(n.begin() + a, n.end()));
  }
  else
  {
    return (sort(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void Reve(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (reverse(n.begin() + a, n.end()));
  }
  else
  {
    return (reverse(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void V(T &n)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i];
  }
}

template <typename T, typename U>
void V2(T &n, U &m)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i];
  }
}

template <typename T, typename U, typename W>
void V3(T &n, U &m, W &p)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i] >> p[i];
  }
}

void fYn(bool a)
{
  if (a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  exit(0);
}
//最大公約数
ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}
//最小公倍数
ll lcm(ll a, ll b)
{
  return a * b / gcd(a, b);
}
//複数個の最小公倍数
ll nlcm(vector<ll> numbers)
{
  ll res;
  res = numbers[0];
  for (ll i = 1; i < numbers.size(); i++)
  {
    res = lcm(res, numbers[i]);
  }
  return res;
}
//累乗(xのn乗%mod)
ll mod_pow(ll x, ll n, ll mod = MAX)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//大文字->小文字(+32)
//少数はなるべく整数に

void Main()
{
  ll a;cin>>a;
  fin(3 * a * a);
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
K = int(input())
X,Y = map(int,input().split())

ans = [(X,Y)]
x,y = ans[-1]
while abs(x)>=3*K//2:
    x,y = ans[-1]
    if x>=K:
        x -= K
    elif x<=-K:
        x += K
    ans.append((x,y))
dx = abs(x)

while abs(y)>2*K-dx:
    x,y = ans[-1]
    if y>0:
        y -= K
    else:
        y += K
    ans.append((x,y))

x,y = ans[-1]
if abs(y)+abs(x)!=K:
    if (x+y)%2==0 and K%2==0:
        d2 = (abs(x)+abs(y))//2
        if abs(x)>abs(y):
            x -= d2 * (1 if x>0 else -1)
            y += (K-d2) * (1 if y>0 else -1)
        else:
            x += (K-d2) * (1 if x>0 else -1)
            y -= d2 * (1 if y>0 else -1)
        ans.append((x,y))
    else:
        if (x+y+K)%2 == 0:
            y -= K if y>0 else (-K)
            ans.append((x,y))
        d = abs(x)+abs(y)
        if abs(x)>abs(y):
            x -= d//2 * (1 if x>0 else -1)
            y += (K-d//2) * (1 if y>0 else -1)
        else:
            x += (K-d//2) * (1 if x>0 else -1)
            y -= d//2 * (1 if y>0 else -1)
        ans.append((x,y))
x,y = ans[-1]

if abs(x)+abs(y)!=K:
    print(-1)
else:
    ans = ans[::-1]
    print(len(ans))
    for out in ans:
        print(*out)

Measured memory_bytes: 26104
#include <stdio.h>

int main(){
    int n;
    int b[100];
    int i;
    scanf("%d",&n);
    for(i= 0; i<n-1; i++){
        scanf("%d",&b[i]);
    }

    int ans=b[0];
    for(i=1; i<n-1; i++){
        if(b[i-1]<b[i]){
            ans+=b[i-1];
        }
        else {
            ans+=b[i];
        }
    }
    ans+=b[i-1];
    printf("%d",ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
  ll N,M; cin >> N>>M;
  ll k=0;
  vector<int> a(M,0);  
  for(int i=0; i<M; i++){
    cin >> a[i] ;
    k += a[i];
  }
  if(N-k<0){
    cout << -1 << endl;
  }
  else{cout << N - k << endl;}
  return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = a + b;
		Double num = Double.parseDouble(c);
		if (Math.sqrt(num) % 1 == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}

}


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

using namespace std;

int main()
{
    int n,i,j,c=0;

    cin>>n;

    string s;
    //for(i=0)

    cin>>s;
    /*j=n/2;
    if(n%2==0)
    {
    for(i=0;i<n/2;i++)
    {
        if(s[i]==s[j])
            c=1;
        else
        {
            c=0;
            break;
        }
        j++;
    }
    if(c)
        cout<"Yes\n";
    else
        cout<<"No\n";
    }

    else
    {
        cout<<"No\n";
    }*/

if(n%2==0)
{
   string s1=s.substr(0,(n+1)/2);//n odd/even devide ans will remain int 6=--3,5=--3
string s2=s.substr((n+1)/2,n-(n+1)/2);//start,length

   if(s1==s2)
    cout<<"Yes\n";
   else
    cout<<"No\n";
}

else
    cout<<"No\n";

    return 0;
}


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

int main(){
  ll X,Y;cin>>X>>Y;
  ll ans=0;
  while(X<=Y){
    X*=2;
    ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,N;
  cin>>N;
  double x;
  vector<vector<double>> dp(N+1,vector<double>(N+1,0));
  dp[0][0]=1;
  rep1(i,N+1){
    cin>>x;
    rep(j,i){
      dp[i][j]+=dp[i-1][j]*(1-x);
      dp[i][j+1]+=dp[i-1][j]*x;
    }
  }
  x=0;
  For(i,N/2+1,N+1){
    x+=dp[N][i];
  }
  cout<<x<<endl;
  return 0;
}

Measured memory_bytes: 141056
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}


ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

const int M=1000;
ll F[M],inv[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
	for(int i=0;i<M;i++) inv[i]=Div(1,F[i]);
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}
const int N=305;
ll n;
vvl dp;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	Init();
	cin>>n;
	dp=vvl(n+1,vl(2*n+1));
	dp[0][0]++;
	bool B=1;
	for(int i=0;i<n;i++){
		vvl DP(n+1,vl(2*n+1));
		int x;
		cin>>x;
		if(x!=2) B=0;
		if(x>1){
			for(int j=0;j<n;j++) for(int k=0;k<=2*n-x+2;k++) (DP[j+1][k+x-2]+=dp[j][k]*inv[x-2])%=mod;
		}
		for(int j=0;j<=n;j++) for(int k=0;k<=2*n;k++) (DP[j][k]+=dp[j][k]*inv[x-1])%=mod;
		dp=DP;
	}
	if(B){
		cout<<Div(F[n-1],2)<<endl;
		return 0;
	}
	ll res=0;
	for(int i=3;i<n;i++) for(int j=1;j<=2*n;j++) (res+=dp[i][j]*F[n-i-1]%mod*j%mod*Div(F[i-1],2))%=mod;
	cout<<res<<endl;
}

Measured memory_bytes: 3184
#include <iostream>
#include <algorithm>
#include <map>

int main() {
    int n;
    std::cin >> n;
    if(n == 1) std::cout << "Hello World" << std::endl;
    else{
        int a,b;
        std::cin >> a >> b;
        std::cout << a+b << std::endl;
    }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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

int main() {
  double n,k;
  cin>>n>>k;
  
  double ans=0;
  for(int i=1;i<n+1;i++){
    double b=i,d=1/n;
    while(b<k){
      b*=2;
      d/=2;
    }
    ans+=d;
  }
  cout << fixed << setprecision(12) << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <set>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

int main() {
  int x, y;
  while (cin >> x >> y) {
    int res = 2100000000;
    // x->y
    if (x <= y) res = min(res, y - x);
    // x->-x->y
    if (-x <= y) res = min(res, 1 + y - (-x));
    // x->-y->y
    if (x <= -y) res = min(res, 1 + (-y - x));
    // x->-x->-y->y
    if (-x <= -y) res = min(res, 2 + (-y - (-x)));

    cout << res << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
void hoandoi(int &c,int &b)
{
	int t=c;c=b;b=t;
}


int main(){
	int n,*a,d=0,min;
	cin>>n;
	a=new int[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n-1;i++)
	{
		min=i;
		for(int j=i+1;j<n;j++){
			if(a[j]<a[min]){
				min=j;
			}
		}
		if(min!=i){
			hoandoi(a[i],a[min]);
			d++;}
	}
	for(int i=0;i<n;i++)
		{cout<<a[i];
		if(i<n-1)
			cout<<" ";
	}
	cout << endl << d << endl;

	return 0;
}

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

int main(){
    int N;
    cin >> N;
    int h[N];
    int i;
    for(i=0;i<N;i++)cin >> h[i];
    int tmp=h[0];
    int flag=0;
    for(i=0;i<N;i++){
        tmp=max(tmp,h[i]);
        if(tmp>h[i]+1)flag++;
    }
    if(flag>0)cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    ll n;
    cin>>n;
    string ans="";
    while(n!=0){
        if(n%2 != 0){//奇数のとき
            n--;
            ans="1"+ans;
        }else{
            ans="0"+ans;
        }
        n/=-2;
    }
    if(ans==""){
        ans="0";
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    if(s.matches(".*keyence")||s.matches("k.*eyence")||s.matches("ke.*yence")||s.matches("key.*ence")||s.matches("keye.*nce")||s.matches("keyen.*ce")||s.matches("keyenc.*e")||s.matches("keyence.*"))
      System.out.println("YES");
    else System.out.println("NO");
  }
}

Measured memory_bytes: 22996
#include <cctype>
#include <string>
#include <iostream>
 
using namespace std;
 
int main()
{
    string S;
     
    getline(cin, S);
     
    for(int i = 0; i < S.size(); i++)
    {
        if(islower(S[i]))
        {
            cout << (char)toupper(S[i]);
        }
        else if(isupper(S[i]))
        {
            cout << (char)tolower(S[i]);
        }
        else
        {
            cout << S[i];
        }
    }
     
    cout << endl;
     
    return 0;
}


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

//#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define LL long long

int main() {
	int a, b;
	cin >> a >> b;
	cout << a*b << endl;
	return 0;
}


Measured memory_bytes: 3636
// 0185
#include <iostream>
#define  N   1000001
using namespace std;

int main(){
	bool prime[N];
	for(int i=2;i<N;i++)
		prime[i] = true;

	for(int i=4;i<N;i+=2)
		prime[i] = false;

	for(int i=3;i<N;i+=2)
		if(prime[i])
			for(int j=2*i;j<N;j+=i)
				prime[j] = false;
	
	while(1){
		int n, count = 0;
		cin>>n;

		if(n == 0)
			break;

		if(prime[2] && prime[n-2])
			count++;

		for(int i=3;i<=n/2;i++)
			if(prime[i] && prime[n-i])
				count++;

		cout<<count<<endl;
	}

	return 0;
}

Measured memory_bytes: 2136
#include <stdio.h>
typedef struct Dice{
	int	f1;
	int	f2;
	int	f3;
	int	f4;
	int	f5;
	int	f6;
	int tmp;
}Dice;

int main(void)
{
	int i;
	Dice D0, D1;
	scanf("%d%d%d%d%d%d", &D0.f1, &D0.f2, &D0.f3, &D0.f4, &D0.f5, &D0.f6);
	scanf("%d%d%d%d%d%d", &D1.f1, &D1.f2, &D1.f3, &D1.f4, &D1.f5, &D1.f6);
	i=0;
	while(D1.f1 != D0.f1){
		D0.tmp = D0.f1;
		i++;
		switch(i%2){
			case 0:
				D0.f1 = D0.f4;
				D0.f4 = D0.f6;
				D0.f6 = D0.f3;
				D0.f3 = D0.tmp;
				break;
			case 1:
				D0.f1 = D0.f2;
				D0.f2 = D0.f6;
				D0.f6 = D0.f5;
				D0.f5 = D0.tmp;
		}
	}
	for(i=0; i<3; i++){
		if(D1.f2 != D0.f2){
			D0.tmp = D0.f2;
			D0.f2 = D0.f3;
			D0.f3 = D0.f5;
			D0.f5 = D0.f4;
			D0.f4 = D0.tmp;
		}
	}
	if(D1.f3 != D0.f3){
		printf("No\n");	
	}else if(D1.f5 != D0.f5){
		printf("No\n");	
	}else if(D1.f4 != D0.f4){
		printf("No\n");	
	}else{
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
ll a[110000];
int main()
{
   ll n;
   cin>>n;
   ll w=sqrt(n);
   cout << w*w << endl;
       return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n; cin >> n;
	string s; cin >> s;
	for(char &c : s) {
		c = (c - 'A' + n) % 26 + 'A'; 
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
function main(input) {
  const inputs =input.split('\n')
  const [a, b] = inputs[0].split(' ').map(Number)
  if (a > b) {
    console.log(Array.from(new Array(a)).map(e => b).join(''))
  } else {
    console.log(Array.from(new Array(b)).map(e => a).join(''))
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 29564
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();

		if ((A <= 9) && (B <= 9)) {
			System.out.println(A * B);
		} else {
			System.out.println(-1);
		}
		sc.close();
	}
}

Measured memory_bytes: 21844