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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    for(int i = 0; i < M; i++)cin >> A[i];
    sort(A.begin(), A.end());
    vector<int> dis(M - 1);
    for(int i = 0; i < M - 1; i++){
        dis[i] = abs(A[i] - A[i + 1]);
    }
    sort(dis.begin(), dis.end());
    long long ans = 0;
    for(int i = 0; i < M - N; i++){
        ans += dis[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias pred)(int n) {
    foreach(i; 0..n) pred();
}
auto rep(alias pred, T = typeof(pred()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = pred();
    return res;
}

void main() {
    string str = readln.chomp;

    long ans = 0;
    foreach(i; 0..2^^(str.length-1)) {
        size_t k = 0;
        foreach(j; 0..str.length-1) {
            if (i>>j&1) {
                ans += str[k..j+1].to!long;
                k = j+1;
            }
        }
        ans += str[k..$].to!long;
    }
    ans.writeln;
}


Measured memory_bytes: 256
import sys
def input():
	return sys.stdin.buffer.readline()[:-1]

while True:
	n, w, d = map(int, input().split())
	if n == w == d == 0:
		break
	cakes = dict()
	cakes[1] = [w, d]
	for i in range(1, n+1):
		p, s = map(int, input().split())
		w, d = cakes[p]
		for j in range(p, i):
			cakes[j] = cakes[j+1]
		s %= w+d
		if s < w:
			cakes[i] = [min(s, w-s), d]
			cakes[i+1] = [max(s, w-s), d]
		else:
			cakes[i] = [w, min(s-w, w+d-s)]
			cakes[i+1] = [w, max(s-w, w+d-s)]
	print(*sorted(v[0]*v[1] for v in cakes.values()))


Measured memory_bytes: 6028
#include<cstdio>
#include<cstring>
#include<set>
#include<map>
#include<algorithm>
using namespace std;

map<int, set<int> > MP, VIS;

typedef long long LL;
const int N = 1e5 + 10;

int h, w, n, X[N], Y[N];
LL ans[10];

int xl[9]={-2,-2,-2,-1,-1,-1,0,0,0};
int yl[9]={-2,-1,0,-2,-1,0,-2,-1,0};

void solve(int x, int y){
	int xx, yy, cnt, a, b;
	for(int i=0; i<9; i++){
		xx = x + xl[i];
		yy = y + yl[i];
		if(xx < 1 || yy < 1 || xx > h-2 || yy>w-2)	continue;
        if(VIS.count(xx) && VIS[xx].count(yy))	continue;
        VIS[xx].insert(yy);
        cnt = 0;
        for(int j=0; j<9; j++){
			a = xx - xl[j];
			b = yy - yl[j];
			if(MP.count(a) && MP[a].count(b)){
				cnt++;
			}
        }
        ans[cnt]++;
        ans[0]--;
	}
}

int main(){
	scanf("%d %d %d", &h, &w, &n);
    int x, y;
    for(int i=0; i<n; i++){
		scanf("%d %d", &x, &y);
		MP[x].insert(y);
		X[i] = x;
		Y[i] = y;
    }
    memset(ans, 0, sizeof(ans));
    ans[0] = 1LL * (h - 2) * (w - 2);

    for(int i=0; i<n; i++){
        solve(X[i], Y[i]);
    }

	for(int i=0; i<=9; i++){
		printf("%lld\n", ans[i]);
	}

	return 0;
}


Measured memory_bytes: 85376
#include<bits/stdc++.h>
#define int long long
using namespace std;
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; }

const int mod=1e9+7;

void add(int& a,int b){
    a=(a+b)%mod; 
}

signed main()
{
    int H,W; cin>>H>>W;
    vector<string> a(H);
    for(int i=0;i<H;i++){
        cin>>a[i];
    }
    
    vector<vector<int> > dp(H,vector<int>(W));
    dp[0][0]=1;
    for(int i=0;i<H;i++) for(int j=0;j<W;j++){
        if(i+1<H and a[i+1][j]=='.'){
            add(dp[i+1][j],dp[i][j]);
        }
        if(j+1<W and a[i][j+1]=='.'){
            add(dp[i][j+1],dp[i][j]);
        }
    }
    cout<<dp[H-1][W-1]<<endl;
}


Measured memory_bytes: 9216
#!/usr/bin/env python3

def main():
    N = int(input())
    Ws = [int(s) for s in input().split()]
    minimum_diff = 10001
    for T in range(N):
        under_T = 0
        upper_T = 0
        for i in range(T):
            under_T += Ws[i]
        for i in range(T,N):
            upper_T += Ws[i]
        current_diff = abs(under_T - upper_T)
        if minimum_diff > current_diff:
            minimum_diff = current_diff
    print(minimum_diff)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
// ABC141-E  https://atcoder.jp/contests/abc141/tasks/abc141_e

#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;

// ローリングハッシュ
struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    // construct
    RollingHash(const string &S) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }
};

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

    // ロリハ
    RollingHash rh(S);

    int left = 0, right = N/2+1, mid;

    while(right-left>1){
        mid = (left+right)/2;
        map<P, int> mp;
        bool ok{};
        for(int i=0;i+mid<=N;i++){
            P p = rh.get(i, i+mid);
            if(mp[p]){
                if(i+1 - mp[p] >= mid){
                    ok = true;
                    break;
                }
            }
            else mp[p] = i+1;
        }
        if(ok) left = mid;
        else right = mid;
    }
    cout << left << endl;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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 vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll K, A, B; cin >> K >> A >> B;
  ll ans = 1;
  if(A > B) {
    ans += K;
    cout << ans << endl;
  } else {
    if(B - A <= 2) {
      ans += K;
      cout << ans << endl;
    } else if(B - A > 2) {
      ans += (A - 1); K -= (A - 1);
      while(K > 1) {
        K -= 2;
        ans += (B - A);
      }
      if(K == 0) cout << ans << endl;
      else if(K > 0) cout << ans + K << endl;
    }
  }
}

Measured memory_bytes: 3592
//#pragma GCC target ("avx2,sse2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree <pair <ll, int>, null_type, less <pair <ll, int> >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define db double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define fi first
#define se second
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define endl "\n"

#define left fsdsdfoisf
#define sum dpsdfioppsf
#define assign xcvjlkdjfio
#define trie fksdfkjkfnjuiv
#define next sidlfjsfkl
#define merge sdfksdkfsldf

//#define int long long

using namespace std;

void dout() {
    cerr << endl;
}
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 21, MOD = 1e9 + 7;
int n, a[N][N], dp[N + 1][(1 << N)];

void add(int & x, int y) {
    x += y;
    if (x >= MOD) {
        x -= MOD;
    }
}

void solve(int tc) {
    // check for (int i = 0; i < n; j++)
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    dp[0][0] = 1;
    for (int mask = 1; mask < (1 << n); mask++) {
        int k = __builtin_popcount(mask);
        for (int i = 0; i < n; i++) {
            if (a[k - 1][i] && (mask & (1 << i))) {
                add(dp[k][mask], dp[k - 1][mask ^ (1 << i)]);
            }
        }
    }
    cout << dp[n][(1 << n) - 1];
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int tc = 1;
//    cin >> tc;
    for (int i = 0; i < tc; i++) {
        solve(i);
//        cleanup();
    }
}


Measured memory_bytes: 162048
program main
  
  implicit none
  !0858
  integer :: n
  integer,allocatable :: a(:), b(:), c(:)
  integer :: i, sat
  
  read(*,*) n
  allocate( a(n) )
  allocate( b(n) )
  allocate( c(n-1) )
  read(*,*) a
  read(*,*) b
  read(*,*) c
  
  sat = 0 
  do i = 1, n
    sat = sat + b(a(i)) 
    if( a(i) == a(i-1)+1 .and. i > 1 ) then
      sat = sat + c(a(i-1)) 
    end if
  end do
  
  print*, sat
  
end program main


Measured memory_bytes: 384
//
// Created by yuu on 2019-06-22.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>

using namespace std;


int main(void){
    string s;
    cin>>s;

    bool flag = true;


    if(s[0] == s[1])flag = false;
    if(s[1] == s[2])flag = false;
    if(s[2] == s[3])flag = false;

    if(flag){
        cout<<"Good"<<endl;
    }else{
        cout<<"Bad"<<endl;
    }
    return 0;
}

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

int calc(int x) {
    int sum = 0;
    while (x > 0) {
        sum += x % 10;
        x /= 10;
    }
    return sum;
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int ans;
    for (int i = 0; i <= N; i++) {
        int sum = calc(i);
        if (A <= sum && sum <= B) {
            ans += i;
        }
    }
    cout << ans << endl;
}

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

// int main()
// {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
// #endif
// 	ll k;
// 	cin>>k;
// 	ll seq[5]={7,77,777,7777,77777};
// 	ll r=0;
// 	for( ;r<5;r++)
// 	{
// 		if(seq[r]%k==0)
// 		{
// 			cout<<r+1;
// 			break;
// 		}
// 	}
// 	if(r==5)
// 		cout<<-1<<endl;
// }
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	ll n,d;
	cin>>n>>d;
	ll co=0;
	for(ll h=0;h<n;h++)
	{
		ll x,y;
		cin>>x>>y;
		double dis=sqrt(x*x+y*y);
		if(dis<=d)
		{
			co++;
		}
	}
	cout<<co<<endl;
}


Measured memory_bytes: 3516
using System;
using System.Linq;

class Procon
{
  public Procon() {}
  static void Main(string[] agrs)
  {
    new Procon().Do();
  }

  Scanner cin;

  public void Do()
  {
    cin = new Scanner();
    int n = cin.nextInt();
    long[] t = new long[n];
    for (int i = 0; i<n; i++) {
      t[i] = cin.nextLong();
    }

    long ret = 1;
    for (int i = 0; i<n; i++) {
      ret = (t[i] / ecd(t[i], ret)) * ret;
    }
    Console.WriteLine(ret);
  }

  static long ecd(long a, long b) {
    if (a < b) {
      long t = a;
      a = b;
      b = t;
    }
    while(true) {
      long r = a % b;
      if (r == 0) 
      {
        return b;
      }
      a = b;
      b = r;
    }
  }
}

class Scanner
{
  string[] s;
  int i;
  int max_i;

  public Scanner()
  {
    s = new string[0];
    max_i = 0;
    i = 0;
  }

  public string nextString()
  {
    if (i >= s.Length) 
    {
      s = Console.ReadLine().Split(' ');
      max_i = s.Length;
      i = 0;
      if (max_i == 0) 
      {
        return "";
      }
      return s[i++];
    } else 
    {
      return s[i++];
    }
  }

  public int nextInt()
  {
    return int.Parse(nextString());
  }


  public long nextLong()
  {
    return long.Parse(nextString());
  }

  public double nextDouble()
  {
    return double.Parse(nextString());
  }

  public string[] arrayString()
  {
    return Console.ReadLine().Split(' ');
  }

  public int[] arrayInt()
  {
    string[] str = Console.ReadLine().Split(' ');
    int[] array = new int[str.Length];
    for (int i=0; i<str.Length; i++) 
    {
      array[i] = int.Parse(str[i]);
    }
    return array;
  }

  public long[] arrayLong()
  {
    string[] str = Console.ReadLine().Split(' ');
    long[] array = new long[str.Length];
    for (int i=0; i<str.Length; i++) 
    {
      array[i] = long.Parse(str[i]);
    }
    return array;
  }

  public double[] arrayDouble()
  {
    string[] str = Console.ReadLine().Split(' ');
    double[] array = new double[str.Length];
    for (int i=0; i<str.Length; i++) 
    {
      array[i] = double.Parse(str[i]);
    }
    return array;
  }
}


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

int main(){
  ll n,d,x;
  cin >> n >> d >> x;
  
  vector<ll> A(n);
  ll eat = 0;
  rep(i,n){
    cin >> A[i];
    rep(j,d){
      if(j*A[i]+1 <= d) eat++;
    }
  }
  ll ans = eat + x;
  cout << ans << endl;
}

Measured memory_bytes: 3556
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;

    int x;
    cin >> x;

    if (x == 7 || x == 5 || x == 3)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
/**
 *      AGC 4 A
 *      author  : kyomukyomupurin
 *      created : 2018-10-11 20:31:15
**/

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define int64 long long
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int64 A[3] = {};
    for (auto i = 0; i < 3; ++i) {
        cin >> A[i];
    }

    if (A[0] % 2 == 0 || A[1] % 2 == 0 || A[2] % 2 == 0) cout << 0 << endl;
    else {
        sort(A, A + 3);
        cout << A[0] * A[1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#define LL long long
#define inl inline
#define re register
#define MAXN 201000
using namespace std;
struct dig
{
	int d;
	LL c;
}g[MAXN];
int m;
int map[11][11],t[11][11];
int now;
LL ans;
void push(int x){ans+=t[now][x];now=map[now][x];}
void work(int d,LL c)
{
	if(c==0)return ;
	ans+=c/2*t[d][d];
	if(c&1)push(d);
	work(map[d][d],c/2);
}
int main()
{
	scanf("%d",&m);
	for(int i=0;i<=9;i++)
		for(int j=0;j<=9;j++)
		{
			map[i][j]=i+j;t[i][j]=1;
			while(map[i][j]>=10)
			{
				map[i][j]=map[i][j]/10+map[i][j]%10;
				t[i][j]++;
			}
		}
	for(int i=1;i<=m;i++)
	{
		int d;LL c;
		scanf("%d%lld",&d,&c);
		work(d,c);
	}
	cout<<ans-1;
	return 0;
}



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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    for (;;) {
        int n, m; cin >> n >> m;
        swap(n, m);
        if (!n && !m) break;

        vector<vi> mp(n, vi(m, 0));
        vector<vi> vis(n, vi(m, 0));
        rep(i, 0, n) rep(j, 0, m) cin >> mp[i][j];

        int ans = 0;
        rep(i, 0, n) rep(j, 0, m) if (!vis[i][j] && mp[i][j] == 1) {
            queue<pii> q;
            q.push({i, j});
            vis[i][j] = true;

            while (!q.empty()) {
                pii p = q.front(); q.pop();
                for (int i = -1; i <= 1; i++)
                    for (int j = -1; j <= 1; j++)
                        if (p.first + i >= 0 && p.first + i < n && p.second + j >= 0 && p.second + j < m && !vis[p.first + i][p.second + j] && mp[p.first + i][p.second + j]) {
                            vis[p.first + i][p.second + j] = 1;
                            q.push({p.first + i, p.second + j});
                        }
            }

            ans++;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
#define time cerr << (0.1 * clock()) / CLOCKS_PER_SEC << endl;
#define mod 1000000007
typedef long long ll;
typedef pair<ll, ll> pl;
#define forn(n) for (ll i = 0; i < ll(n); i++)

void solve() {
    char a;
    cin >> a;
    if(a < 'a'){
        cout << "A\n";
        return;
    }
    cout << "a\n";
}

int main() {
    quick;
    solve();
    // ll t;
    // cin >> t;
    // while (t--) {
    //     solve();
    // }
}

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

int main() {
  int N ;
  cin >> N;
  vector<int>vec(N);
  double sum ;
  
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
    sum+=1.0/vec.at(i);
  }
  cout<<1.0/sum<<endl;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <string>
#include <climits>
using namespace std;

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

class state{
public:
  int x,y,dir,cost;
  state(int _x, int _y, int _d, int _c){
    x=_x;
    y=_y;
    dir=_d;
    cost=_c;
  }
  bool operator<(const state& a)const{
    return cost > a.cost;
  }
};
const int dx[] = {0,1,0,-1};
const int dy[] = {-1,0,1,0};
int w,h;
int field[32][32];
int dp[4][32][32];
int C[4];

bool inside(int x, int y){
  return !(x<0 || y<0 || x>=w || y>=h);
}

int main(){
  int i,j,k;
  while(cin>>w>>h,w|h){
    rep(i,4)rep(j,32)rep(k,32)dp[i][j][k]=INT_MAX;
    rep(i,h){
      rep(j,w){
	cin>>field[i][j];
      }
    }
    scanf("%d%d%d%d",C,C+1,C+2,C+3);

    int ans = -1;
    priority_queue<state> q;
    dp[1][0][0] = 0;
    q.push(state(0,0,1,0));
    while( !q.empty() ){
      int x = q.top().x;
      int y = q.top().y;
      int dir = q.top().dir;
      int cost = q.top().cost;
      q.pop();
      
      if( x==w-1 && y==h-1 ){
	ans = cost;
	break;
      }
#if DEB
      printf("(%d,%d) dir:%d, cost:%d\n",x,y,dir,cost);
#endif

      rep(k,4){
	int nextdir = (dir+k)%4;
	int tx = x + dx[nextdir];
	int ty = y + dy[nextdir];
	if( !inside(tx,ty) )continue;
	
	if( field[y][x] == k ){
	  if( dp[nextdir][ty][tx] > cost ){
	    dp[nextdir][ty][tx] = cost;
	    q.push(state(tx,ty,nextdir,cost));
	  }
	}else{
	  if( dp[nextdir][ty][tx] > cost + C[k] ){
	    dp[nextdir][ty][tx] = cost + C[k];
	    q.push(state(tx,ty,nextdir,cost+C[k]));
	  }
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1068
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
const double PI=3.14159265358979323846;

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

  double r;
	cin >> r;
	cout << 2 * r * PI << "\n";
}


Measured memory_bytes: 3236
n = int(input())
s = input()
rl = 0
gl = 0
bl = 0
for i in range(n):
	if s[i] == 'R':
		rl += 1
	elif s[i] == 'G':
		gl += 1
	else:
		bl += 1
ans = rl*bl*gl
cnt = 0
for i in range(1,n//2+3):
	j = 0
	while j+i+i < n:
		if (s[j] == 'R'):
			if (s[j+i] == 'B'):
				if (s[j+i+i] == 'G'):
					cnt += 1
			elif (s[j+i] == 'G'):
				if (s[j+i+i] == 'B'):
					cnt += 1
		elif (s[j] == 'G'):
			if (s[j+i] == 'B'):
				if (s[j+i+i] == 'R'):
					cnt += 1
			elif (s[j+i] == 'R'):
				if (s[j+i+i] == 'B'):
					cnt += 1
		else:
			if (s[j+i] == 'R'):
				if (s[j+i+i] == 'G'):
					cnt += 1
			elif (s[j+i] == 'G'):
				if (s[j+i+i] == 'R'):
					cnt += 1
		j+=1
print(ans-cnt)

Measured memory_bytes: 9284
<?php
	$s=[];
	for($i=0;$i<3;$i++)$s[]=chop(fgets(STDIN));
	$c=[0,0,0];
	$f=0;
	while($c[$f]<strlen($s[$f]))
	{
		$c[$f]++;
		$f=ord($s[$f][$c[$f]-1])-97;
	}
	echo chr($f+65);

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define mk make_pair
#define vec vector<int> 
#define finput ifstream cin;cin.open("in.txt")
#define foutput ofstream cout;cout.open("out.txt")
#define mod 1000000007LL 
int prime[100001]={0};vector <int> p;
void sieve(){
	for(int i=2;i*i<=100000;i++){
		if(prime[i]==0){
			for(int j=2*i;j<=100000;j+=i){
				prime[j]=1;
			}
		}
	}
	for(int i=2;i<=100000;i++){
		if(prime[i]==0){
			p.push_back(i);
		}
	}
}
ll int func(ll int n,ll int r){ 
    ll int C[r+1]; 
    memset(C, 0, sizeof(C)); 
    C[0] = 1; 
    for (int i = 1; i <= n; i++){
        for (int j = min((ll)i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%mod; 
    }
    return C[r];
}
int main(){
	//finput;foutput;
	ios_base::sync_with_stdio(false);
	ll int n,temp;
	ll int m,ans=1;
	cin>>n>>m;
	vector<ll int> cc;
	sieve();
	for(int i=0;i<p.size();i++){
		temp=0;
		while(m%p[i]==0){
			temp++;
			m/=p[i];
		}
		if(temp>0)	cc.push_back(temp);
	}
	if(m!=1) cc.push_back(1);
	for(int i=0;i<cc.size();i++){
		//cout<<func(n,cc[i])<<" ";
		ans*=func(n+cc[i]-1,cc[i]);
		ans%=mod;
	}
	cout<<ans;
}

Measured memory_bytes: 768
import numpy as np
N = int(input())
XY = np.array([list(map(int,input().split())) for _ in [0]*N])
th = np.arctan2(XY[:,1],XY[:,0])
XY = XY[th.argsort()]
ans = 0
n = np.linalg.norm
Sxy = np.vstack((np.zeros(2),np.cumsum(XY,axis=0)))
i=0
j=1
pr = 0
while i<N:
        r = n(Sxy[min(j,N)]-Sxy[i] + Sxy[max(0,j-N)])
        if r>=pr and j<i+N+1 : j+=1
        else:
            i += 1
            j = max(j-1,i+1)
            r = 0
        ans = max(ans,r)
        pr = r
print(ans)

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

void dijkstra(vector<int> &S, int K) {
    using P = pair<int, int>;

    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(S[1], 1);

    while(!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if(S[v] < p.first) continue;

        for(int y=0; y<10; ++y) {
            int nv = (10 * v + y) % K;
            if(S[nv] > S[v] + y) {
                S[nv] = S[v] + y;
                que.emplace(S[nv], nv);
            }
        }
    }
}

int digitsum(int x) {
    int ret = 0;
    while(x > 0) {
        ret += x % 10;
        x /= 10;
    }
    return ret;
}

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

    vector<int> S(K, 100100101);
    for(int i=1; i<min(10, K); ++i) S[i] = digitsum(i);

    dijkstra(S, K);
    cout << S[0] << endl;
}

Measured memory_bytes: 2804
class Dice:
    __TOP = 0
    __FRONT = 1
    __RIGHT = 2
    __LEFT = 3
    __BACK = 4
    __BOTTOM = 5

    def __init__(self, face_val=None):
        self.f_keys = [self.__TOP,  # 0
                       self.__FRONT,  # 1
                       self.__RIGHT,  # 2
                       self.__LEFT,  # 3
                       self.__BACK,  # 4
                       self.__BOTTOM  # 5
                       ]

        if face_val is None or len(face_val) != 6:
            face_val = ['1', '2', '3', '4', '5', '6']

        self.f_key_to_val = {}
        self.f_val_to_key = {}
        for f_key, val in zip(self.f_keys, face_val):
            self.f_key_to_val[f_key] = val
            self.f_val_to_key[val] = f_key

    MOVE_SWAP_FACES = {
        'S': [(__BACK, __TOP), (__TOP, __FRONT), (__FRONT, __BOTTOM), (__BOTTOM, __BACK)],
        'W': [(__RIGHT, __TOP), (__TOP, __LEFT), (__LEFT, __BOTTOM), (__BOTTOM, __RIGHT)],
        'E': [(__LEFT, __TOP), (__TOP, __RIGHT), (__RIGHT, __BOTTOM), (__BOTTOM, __LEFT)],
        'N': [(__FRONT, __TOP), (__TOP, __BACK), (__BACK, __BOTTOM), (__BOTTOM, __FRONT)],
        'RCW' : [(__LEFT, __FRONT), (__FRONT, __RIGHT), (__RIGHT, __BACK), (__BACK, __LEFT)],   # rotate clockwise
        'RCCW': [(__RIGHT, __FRONT), (__FRONT, __LEFT), (__LEFT, __BACK), (__BACK, __RIGHT)],   # rotate counter clockwise
    }

    def dice_move(self, direction_list):
        for direction in direction_list:
            prev_faces = self.f_keys[:]
            for prev_f, next_f in self.MOVE_SWAP_FACES[direction]:
                self.f_keys[next_f] = prev_faces[prev_f]
            #print(self.f_keys)

    MOVE_TO_TOP = {__TOP:[], __FRONT:['N'], __RIGHT:['W'], __LEFT:['E'], __BACK:['S'], __BOTTOM:['N','N']}

    def dice_fix(self, top, front):
        if type(top) == str:
            top = self.f_val_to_key[top]
            front = self.f_val_to_key[front]

        # 上面を指定された面にする
        if top != self.f_keys[self.__TOP]:
            now_top = self.f_keys.index(top)
            move = self.MOVE_TO_TOP[now_top]
            self.dice_move(move)

        if top != self.f_keys[self.__TOP]:
            raise AssertionError # not top

        # 全面を指定された面にする
        if front != self.f_keys[self.__FRONT]:
            for i in range(3):
                self.dice_move(['RCW'])
                if front == self.f_keys[self.__FRONT]:
                    break
            else:
                raise AssertionError    # 3回回転するうちに指定された面がfrontに来ないとおかしい

    def get_value(self, face):
        return self.f_key_to_val[self.f_keys[face]]

    def __repr__(self):
        return f'({",".join(map(str, self.f_keys))})'


faces = input().split()
nq = int(input())

dice = Dice(faces)
for q in range(nq):
    top_val, front_val = input().split()
    dice.dice_fix(top=top_val, front=front_val)
    print(dice.get_value(Dice._Dice__RIGHT))


Measured memory_bytes: 5628
S = input()
l = len(S)
bw = '01' * (l // 2 + 1)
wb = '10' * (l // 2 + 1)
bw_count = len([ 1 for a, b in zip(S, bw) if a != b  ])
wb_count = len([ 1 for a, b in zip(S, wb) if a != b  ])
print(min(bw_count, wb_count))


Measured memory_bytes: 4212
#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++)
typedef long long ll;

int main() {
    int N;
    cin >> N;
    if (N%2 == 0) {
        cout << N << endl;
    }
    else {
        cout << N*2 << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
long long a[401];
long long p[401];
long long dp[401][401];
long long calc(int i, int j) {
	if (~dp[i][j]) return dp[i][j];
	else if (i == j) return dp[i][i] = 0;
	else {
		for (int k = i; k <= j; k++) {
			if (~dp[i][j]) dp[i][j] = min(dp[i][j], calc(i, k) + calc(k + 1, j) + p[k] - p[i - 1] + p[j] - p[k]);
			else dp[i][j] = calc(i, k) + calc(k + 1, j) + p[k] - p[i - 1] + p[j] - p[k];
		}
		return dp[i][j];
	}
}
int main() {
	int N; cin >> N;
	for (int i = 1; i <= N; i++) cin >> a[i];
	for (int i = 1; i <= N; i++) p[i] = p[i - 1] + a[i];
	memset(dp, 0xff, sizeof(dp));
	cout << calc(1, N) << endl;
}


Measured memory_bytes: 1536
#include<stdio.h>
#define MAX 100000

int parent(int i){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}

int main(){
  int H,i,A[MAX+1];
  scanf("%d",&H);
  for(i=1;i<=H;i++)scanf("%d",&A[i]);
  for(i=1;i<=H;i++){
    printf("node %d: ",i);
    printf("key = %d, ",A[i]);
    if(parent(i)>=1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<= H)printf("left key = %d, ",A[left(i)]);
    if(right(i)<=H)printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2104
def main():

	numbers = input().split()
	a, b, c = map(int, numbers)

	a_to_b = list(range(a, b + 1))    #a to b
	result = [x for x in a_to_b if c % x == 0]
	#約数検索
	count = int(len(result))
	print(count)
	


if __name__=="__main__":
	main()

Measured memory_bytes: 7028
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);
    int age = cin.nextInt();
    int cost = cin.nextInt();

    if (age >= 13) {
      System.out.println(cost);
    }
    else if (age>=6 && age<=12) {
      System.out.println(cost/2);
    }
    else {
      System.out.println(0);
    }
  }

}


Measured memory_bytes: 22228
#include<iostream>
#include<vector>
#include<utility>
#include<math.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int> > vp;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define For(i, a, n) for(int i = a; i < (n); i++)
#define out(n) cout << (n) << endl;
#define vut(v) rep(i, v.size()) out(v[i]);

int main(){
  int n, t, ans = 0;
  cin >> n >> t;

  int a[n];
  rep(i, n) cin >> a[i];

  rep(i, n - 1) {
    ans += a[i + 1] - a[i] < t ? a[i + 1] - a[i] : t;
  }

  ans += t;

  out(ans)
}


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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

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

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

    int a;
    cin >> a;
    cout << (a + a * a + a*a*a) << endl;
    return 0;
}



Measured memory_bytes: 3688
// In the name of god
#include <bits/stdc++.h>
#pragma GCC optimze("02")
#define F first
#define S second
#define pb push_back
using namespace std;
using ll = long long;
const ll maxn=1e5+5,inf=1e18+18;
ll a,b,c,x;
int main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
	cin>>a>>b>>c>>x;
	while(b<=a){
		b*=2;
		x--;
	}
	while(c<=b){
		c*=2;
		x--;
	}
	if(x>=0)cout<<"Yes";
	else cout<<"No";
}


Measured memory_bytes: 3632
N = int(input())
li = [ [int(it) for it in input().split()] for i in range(N)]

X,Y=-1,-1
for x in range(101):
  for y in range(101):
    flag = True
    _h = -1
    for i,j,h in li:
      kyo = abs(i-x)+abs(j-y)
      if (h>0):
        if (_h==-1):
          _h = kyo + h
        else:
          if (_h!=kyo+h):
            flag=False
            break
      else: #h==0
        if (_h>kyo):
          flag=False
          break
    for i,j,h in li:
      kyo = abs(i-x)+abs(j-y)
      if (h>0):
        if (_h==-1):
          _h = kyo + h
        else:
          if (_h!=kyo+h):
            flag=False
            break
      else: #h==0
        if (_h>kyo):
          flag=False
          break
    if (flag):
      X = x
      break
  if (flag):
    Y = y
    break
print (X,Y,_h)


Measured memory_bytes: 44908
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rp(i,x,y) for(register ll i=x;i<=y;++i)

int h,w;
bool QwQ[510][510];

inline ll read()
{
    char ch=getchar();ll x=0;bool y=1;
    while(ch!='-' && (ch>'9' || ch<'0'))ch=getchar();
    if(ch=='-')ch=getchar(),y=0;
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
    return y?x:-x;
}
inline char rdch()
{
	char ch;cin>>ch;return ch;
}

int main()
{
	h=read();w=read();memset(QwQ,0,sizeof(QwQ));
	rp(i,1,h)
		rp(j,1,w){char ch=rdch();if(ch=='#')QwQ[i][j]=1;}
		
//	cout<<endl<<endl;
		
	rp(i,1,h)
	{
		printf("#");
		rp(j,2,w-1)
		{
			if(i%2==1 || QwQ[i][j]==1)printf("#");
			else printf(".");
		}
		if(QwQ[i][w]==1)printf("#");else printf(".");
		printf("\n");
	}
	printf("\n");
	rp(i,1,h)
	{
		if(QwQ[i][1]==1)printf("#");else printf(".");
		rp(j,2,w-1)
		{
			if(i%2==0 || QwQ[i][j] || j==w)printf("#");
			else printf(".");
		}
		printf("#");
		printf("\n");
	}
    return 0;
}

Measured memory_bytes: 1024
s = gets.chomp

ary = [s]

for i in 1..s.size-1
  j = s.size()-1 - i
  tmp = []
  ary.each{|str|
    tmp << str
    x = str[0..j] + " " + str[(j+1)..(-1)]
    tmp << x
  }
  ary = tmp
  #p ary
end

ans = 0
ary.each{|str|
  ans += str.split(" ").map{|al| al.to_i}.inject(:+)
}
puts ans




Measured memory_bytes: 1788
import java.util.*;

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

	int n = sc.nextInt();
	while(sc.hasNext()){
	    int[] num = new int[10];
	    for(int i=0; i<num.length; i++){
		num[i] = sc.nextInt();
	    }

	    int[] right = new int[10];
	    int[] left = new int[10];

	    right[0] = num[0];
	    int countR = 1;
	    int countL = 0;
	    String ans = "YES";
	    for(int i=1; i<num.length; i++){
		if(right[countR-1]<num[i]){right[countR] = num[i]; countR++;}
		else{
		    if(countL==0){left[countL] = num[i]; countL++;}
		    else if(left[countL-1]<num[i]){left[countL] = num[i]; countL++;}
		    else {ans = "NO"; break;}
		}
	    }
	    System.out.println(ans);
	}
    }
}

Measured memory_bytes: 12000
#include <stdio.h>

int main(){
        double a,b;
        int ave2;
        scanf("%lf %lf",&a,&b);
        double ave;
        ave = (a+b)/2;
        ave2 = (a+b)/2;
        if(ave == ave2){
                printf("%d\n", ave2);
        }
        if(ave > ave2){
                printf("%d\n", ave2+1);
        }
        return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	private class HashSet {

		private int M = 1046527;
		private String[] H = new String[M];
		
		private int getChar(char ch) {
			if (ch=='A') return 1;
			else if (ch=='C') return 2;
			else if (ch=='G') return 3;
			else if (ch=='T') return 4;
			else return 0;
		}
		
		private int getKey(String str) {
			int sum = 0, p = 1;
			for (int i = 0; i < str.length(); i++) {
				sum += p*(getChar(str.charAt(i)));
				p *= 5;
			}
			return sum;
		}

		private int h1(int key) {return key % M;}
		private int h2(int key) {return 1 + (key % (M-1));}

		public boolean find(String str) {
			int key, i, h;
			key = getKey(str);
			for (i = 0 ;; i++) {
				h = (h1(key) + i * h2(key)) % M;
				if (H[h] != null && H[h].equals(str)) return true;
				else if (H[h] == null || H[h].length() == 0) return false;
			}
		}
		
		public void insert(String str) {
			int key, i, h;
			key = getKey(str);
			for (i = 0 ;; i++) {
				h = (h1(key) + i * h2(key)) % M;
				if (H[h] != null && H[h].equals(str)) return;
				else if (H[h] == null || H[h].length() == 0) {
					H[h] = new String(str);
					return;
				}
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		HashSet set = new HashSet();
		int n = Integer.parseInt(reader.readLine());
		for (int i = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(reader.readLine());
			String cmd = st.nextToken();
			String str = st.nextToken();
			if (cmd.equals("insert")) {
				set.insert(str);
			} else if (cmd.equals("find")) {
				if (set.find(str)) {
					System.out.println("yes");
				} else {
					System.out.println("no");
				}
			}
		}
		reader.close();
	}
}



Measured memory_bytes: 128484
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>

#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define LLINF (1<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

int main() {
    int n, ans=0;
    cin >> n;
    for (int i = 1; i <= n; i++)ans += i;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np
 
N,Max_W = map(int,input().split())
 
dp = [0 for _ in range(Max_W + 1)]
dp = np.array(dp)
 
for i in range(N):
    w,v = map(int,input().split())
    a = dp[:-w] + v
    b = dp[w:]
    m = np.maximum(a,b)
    dp[w:] = m
print(dp[-1])

Measured memory_bytes: 17072
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(5);
    for(int i = 0; i < 5; ++i) {
        cin >> A[i];
    }
    ll min = *min_element(A.begin(), A.end());
    ll ret = (N+min-ll(1))/min + ll(4);
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int N, X, M, i;
    scanf("%d %d %d", &N, &M, &X);
    int A[N][M], C[N];
    int exp[M], reexp[M];
    for(i = 0; i<M; i++){
        exp[i] = 0;
        reexp[i] = 0;
    }
    for(i = 0; i < N; i++){
        scanf("%d", &C[i]);
        for(int j = 0; j < M; j++){
            scanf("%d", &A[i][j]);
            exp[j] += A[i][j];
        }
    }
    //計算を軽くするため、２の12乗までを手動入力
    int ns[13] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096};
    
    //"exp"を使ってまず目標を達成できるかどうかを評価
    int zzzz = 0;
    for(i = 0; i<M; i++){
        if(exp[i] < X) zzzz += 1;
    }
    if(zzzz >= 1) printf("-1\n");
    else{
    //まず全部試すための回数を求める
    int two = 1;
    for(int j = 0; j <= N; j++){
        two *= 2;
    }
    //上記で求めた数を使い全通り試す
        int cost, x, ka, check = 0, recost = 100000000;
    for(int k = 1; k < two - 1; k++){
        for(int m = 0; m < M; m++){
            reexp[m] = 0;
        }
        check = 0;
        cost = 0;
        ka = k;
        for(i = 0; i < N; i++){
            x = N - i;
            if(ka >= ns[x]){
                ka -= ns[x];
                for(int z = 0; z < M; z++)
                    reexp[z] += A[i][z];
                cost += C[i];
            }
        }
        for(int l = 0; l < M; l++){
            if(reexp[l] < X) check += 1;
        }
        if(check == 0){
            if(cost < recost) recost = cost;
        }
    }
        printf("%d", recost);
        
    }
    return 0;

}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[100010],b[100010],c[100010];
int main() {
	string s;
	cin>>s;
	ll cnt=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='R'){
			cnt++;
			if(i==s.size()-1){
				a[i]=cnt;
			}
		}
		else if(i!=0){
			a[i-1]=cnt;
			cnt=0;
		}
	}
	cnt=0;
	for(int i=s.size()-1;i>=0;i--){
		if(s[i]=='L'){
			cnt++;
			if(i==0){
				b[i]=cnt;
			}
		}
		else if(i!=s.size()-1){
			b[i+1]=cnt;
			cnt=0;
		}
	}
	for(int i=0;i<s.size();i++){
		if(a[i]!=0){
			if(i==s.size()){
				c[i]+=a[i];
			}
			else{
			c[i]+=(a[i]+2-1)/2;
			c[i+1]+=a[i]-(a[i]+2-1)/2;
			}
		}
		if(b[i]!=0){
			if(i==0){
				c[i]+=b[i];
			}
			else{
			c[i]+=(b[i]+2-1)/2;
			c[i-1]+=b[i]-(b[i]+2-1)/2;
			}
		}
	}
	for(int i=0;i<s.size();i++){
		cout <<c[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int min = 100000;
	int n; cin >> n;
	vector<int> w(n);
	for (int i = 0; i < n; i++) cin >> w[i];
	int left = 0;
	int right = 0;
	for (int i = 0; i < n; i++) right += w[i];

	for (int i = 0; i < n; i++)
	{
		left += w[i];
		right -= w[i];
		int diff = abs(left - right);
		if (diff < min) min = diff;
	}

	cout << min << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int len = s.length();
        long ans = 0;
        for (int bit = 0; bit < (1 << (len - 1)); bit++) {
            long sum = 0;
            long tmp = (int) (s.charAt(0) - '0');
            for (int i = 0; i < len - 1; i++) {
                // 0なら+ではない
                if ((bit & (1 << i)) != 0) {
                    sum += tmp;
                    tmp = (int) (s.charAt(i + 1) - '0');
                } else {
                    tmp *= 10;
                    tmp = tmp + (int) (s.charAt(i + 1) - '0');
                }
            }
            sum += tmp;
            ans += sum;
        }
        System.out.println(ans);

        sc.close();
    }
}


Measured memory_bytes: 23252
#coding: UTF-8

def PTC(a):
    for i in range(len(a)):
        if a[i] == "0":
            break
        print("Case "+ str(i+1) +": "+a[i])
        

if __name__=="__main__":
    a = []
    for i in range(10000):
        a.append(input())
        if a[i] == "0":
            break
    PTC(a)

Measured memory_bytes: 8128
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int n = scan.nextInt();
      	int K = scan.nextInt();
      	double ans = 0.0;
      	double[] anss = new double[n];
      	for(int i = 1; i <= n; i++){
        	if(i > K - 1){
              	anss[i-1] = 1.0 / n;
            }
          	else{
              	int j = i;
              	int counter = 0;
            	while(j < K){
                	j = j * 2;
                    counter ++;
                }
              anss[i-1] = (1.0/n) * Math.pow(0.5, counter); 
            }
        }
      	for(int k = 0; k < n; k++){
        	ans = ans + anss[k];
        }
      	System.out.print(ans);
    }
 
}

Measured memory_bytes: 23764
import scala.io.StdIn._
import scala.math._

object Main extends App with StdInHelper {
  val a = readInt
  println(a + a * a + a * a * a)
}

trait StdInHelper {
  def readStrings = readLine.split(" ")
  def readInts = readStrings.map(_.toInt)
  def readLongs = readStrings.map(_.toLong)
  def readDoubles = readStrings.map(_.toDouble)
  def readBigInts = readStrings.map(BigInt.apply(_))
  def readBigDecimals = readStrings.map(BigDecimal.apply(_))
}


Measured memory_bytes: 54576
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<random>
using namespace std;

int findI(vector<int>& A, int x)
{
	int ans = INT_MAX;
	for (int i = 1; i <= A.size(); ++i) if (x % A[i - 1] == 0) ans = min(i, ans);
	if (ans == INT_MAX) ans = -1;
	return ans;
}
int main()
{
	vector<int> AN;
	while (1)
	{
		int n, l, r;
		cin >> n >> l >> r;
		if (n == 0) break;
		vector<int> A(n);
		int ans = 0;
		for (int i = 0; i < n; ++i) cin >> A[i];
		for (int x = l; x <= r; ++x)
		{
			int i = findI(A, x);
			if (i != -1 && (i % 2 == 1)) ++ans;
			if (i == -1 && (n % 2 == 0)) ++ans;
		}
		AN.push_back(ans);
	}
	for (const auto& a : AN)
		cout << a << endl;
	return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int solve(string s,long long n){
    if(stoll(s)>n) return 0;
    
    int ans=0;
    vector<bool> check(3,false);
    for(auto a:s){
        if(a=='7') check.at(0)=true;
        if(a=='5') check.at(1)=true;
        if(a=='3') check.at(2)=true;
    }
    
    if(check.at(0) && check.at(1) && check.at(2)) ans++;
    
    vector<string> hoge={"7","5","3"};
    
    for(auto a:hoge){
        ans+=solve(s+a,n);
    }
    
    return ans;
}

int main(){
    long long n;
    cin>>n;
    
    cout<<solve("0",n)<<endl;;
    
    return 0;
}

Measured memory_bytes: 256