akhauriyash/Code-Regression huggingface dataset:
'''import math
#map(int,input().split())
#int(x) for x in input().split()
#for _ in range(int(input())):
n,m,k=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
pa=[0]*n
pb=[0]*m
pa=[a[0]]
pb=[b[0]]
for i in range(n):
	pa[i]=pa[i-1]+a[i]
for i in range(m):
	pb[i]=pb[i-1]+b[i]

'''
n=int(input())
l=[0]*(n+1)
for i in range(1,n+1):
	for j in range(i,n+1,i):
		l[j]+=1

s=0

for i in range(1,n+1):
	s+=i*l[i]
print(s)






Measured memory_bytes: 146036
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,y;
  cin >> n >> y;
  for(int i = 0;i <= n;i++){
    for(int j = 0;j <= n;j++){
      if(i + j > n)continue;
      if((y - i * 10000 - j * 5000) % 1000 == 0 && (y - i * 10000 - j * 5000) / 1000 == n - i - j){
        cout << i << " " << j << " " << n - i - j << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;
typedef pair<int, char> P;


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

    int x, y;
    cin >> x >> y;

    auto it = s.find('T');
    if (it == string::npos) {
        if (s.size() == x && y == 0) {
            cout << "Yes" << endl;
            return 0;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }

    {
        s = s.substr(it);
        x -= it;
    }

    cout << endl;


    vector<int> horizontal;
    vector<int> vertical;
    {
        char direction = 'H';
        int count = 0;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == 'T') {
                if (direction == 'H') {
                    direction = 'V';
                    horizontal.push_back(count);
                    count = 0;
                } else {
                    direction = 'H';
                    vertical.push_back(count);
                    count = 0;
                }
            } else {
                count++;
            }
        }
        if (direction == 'H') {
            horizontal.push_back(count);
        } else {
            vertical.push_back(count);
        }
    }

    sort(vertical.rbegin(), vertical.rend());
    sort(horizontal.rbegin(), horizontal.rend());

    for (int h : horizontal) {
        if (x > 0) {
            x -= h;
        } else {
            x += h;
        }
    }

    for (int v : vertical) {
        if (y > 0) {
            y -= v;
        } else {
            y += v;
        }
    }

    if (x == 0 && y == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            out.println(n * (n + 1) / 2);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
            this.bufPointer = 0;
            this.bufLength = 0;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            int n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

    }
}



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

int main() {
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    map<int, int> mp;
    mp[0] = 1;
    long long s = 0;
    for (int v: a) {
        s += v;
        mp[s%m]++;
    }
    long long ans = 0;
    for (auto pr: mp) {
        long long cnt = pr.second;
        ans += cnt*(cnt-1)/2;
    }
    cout << ans << endl;
}

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

int main() {
    int x;
    cin >> x;
    if (x == 0) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3632
/*  
	Come feed the rain
	Cos I'm thirsty for your love
	Dancing underneath the skies of lust
	Yeah feed the rain...
	Cos without your love my life
	Ain't nothing but this carnival of rust
    _________________________
    _________________________
    864 Hours of Solitude
    Quarantine_Day : 36
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int       ll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef pair<int, int>      pii;
typedef pair<ll, ll>		pll;

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<int>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 50005
#define MOD 1000000007

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

	string s; cin>>s;
	set<char>st;
	REP(i, s.size()) st.insert(s[i]);
	
	cout<<(st.size() == s.size()?"yes\n":"no\n");

	return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[n],i;
    vector<int>v;
    
    for(i=0;i<n;i++) cin>> arr[i];
    
    for(i=0;i<n;i++){
        if(arr[i]%2==0){
            v.push_back(arr[i]);
        }
    }
    int cnt=0;
    for(i=0;i<v.size();i++){
        if(v[i]%3==0 ||v[i]%5==0) cnt++;
    }
    
    if(cnt==v.size()) cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

c = True
for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 != 0 and a[i] % 5 != 0:
            c = False
            print("DENIED")
            break

if c:
    print("APPROVED")

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

template <typename CLASS1, typename CLASS2>
bool operator==(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value == hoge2.value;
};

template <typename CLASS1, typename CLASS2>
bool operator<(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value < hoge2.value;
};

template <typename CLASS1, typename CLASS2>
bool operator>(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value > hoge2.value;
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

vector<vector<pair<ll, ll>>> Path;
vb color;
vb flag;

void search(int pos){
  bool tmp = color[pos];
  for(int i=0; i<Path[pos].size(); ++i){
    int target = Path[pos][i].first;
    if(flag[target]) continue;
    int dist = Path[pos][i].second;
    if(dist%2==0) color[target] = tmp;
    else          color[target] = !tmp;
    flag[target] = true;
    search(target);
  }
  return;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;

  Path.resize(N);
  REP(i, N-1){
    ll u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    Path[u].push_back({v, w});
    Path[v].push_back({u, w});
  }

  flag.resize(N, false);
  color.resize(N);
  flag[0] = true;
  color[0] = true;

  search(0);

  REP(i, N){
    cout << color[i] << "\n";
  }

  return 0;
}


Measured memory_bytes: 9344
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath> // sqrt
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


#define INF (1e+9)
int main(void) {
    int vs, es;
    cin >> vs >> es;

    vector<vector<int>> graph(vs);
    for(int i = 0; i < es; i++) {
        int v1, v2;
        cin >> v1 >> v2;
        v1--; v2--;
        graph[v1].push_back(v2);
        graph[v2].push_back(v1);
    }

    // count, prev
    vector<pii> table(vs, make_pair(INF, 0));
    table[0] = make_pair(0, 0);
    queue<int> queue;
    queue.push(0);

    while(!queue.empty()) {
        int src = queue.front(); queue.pop();
        debug("v: %d\n", src);
        int count = table[src].first;
        for(int dst: graph[src]) {
            if(table[dst].first > count+1) {
                table[dst] = make_pair(count+1, src);
                queue.push(dst);
            }
        }
    }

    bool flag = true;
    for(int i = 0; i < vs; i++) {
        if(table[i].first == INF) flag = false;
    }
    if(flag) {
        cout << "Yes" << endl;
        for(int i = 1; i < vs; i++) {
            cout << table[i].second + 1 << endl;
        }
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 10720
#include<stdio.h>

int main(void){
int a[1000000];

int i,k;
int m=0;
int answer;

scanf("%d",&a[0]);

for(i=1;m<1;i++){
if(a[i-1]%2==0){a[i]=(a[i-1]/2);}
else{a[i]=(3*a[i-1])+1;}
for(k=0;k<i;k++){
if(a[i]==a[k]){answer=i+1;m=1;}
}
}

printf("%d",answer);
return 0;}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
 
const int dy[8] = {1,1,1,0,0,-1,-1,-1};
const int dx[8] = {-1,0,1,-1,1,-1,0,1};
 
int h,w;
string str[10];
 
void solve(){
  int y, x, ansn = 0;
  string ans = "0", st;
  set<string> s;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int k=0;k<8;k++){
        st.clear();
        st += str[i][j];
        y = i;
        x = j;
        while(1){
          y = (y + h + dy[k]) % h;
          x = (x + w + dx[k]) % w;
          if(y == i && j == x) break;
          else st += str[y][x];
          if(!s.empty() && s.find(st) != s.end()){
            if(ansn < st.size() || ansn == st.size() && ans > st){
              ans = st;
              ansn = st.size();
            }
          } else if(st.size() >= ansn) s.insert(st);
        }
 
      }
    }
  }
  cout << ans << endl;
}
 
int main(){
  while(cin >> h >> w && (h|w)){
    for(int i=0;i<h;i++){
      cin >> str[i];
    }
    solve();
  }
}

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

using namespace std;

int h, w, a[10][10], ok, x, y;
char b[10][10];

int main() {

    cin >> h >> w;

    for (int i = 1; i <= h; ++i){
        for (int j = 1; j <= w; ++j){
            cin >> b[i][j];
            if (b[i][j] == '#') a[i][j] = 1;
        }
    }

    a[1][1] = 2;
    ok = 1;
    x = 1;
    y = 1;
    while(ok != 0){
        ok = 0;
        if (a[x][y + 1] == 1) ok = 1;
        else if (a[x + 1][y] == 1) ok = 2;
        if (ok == 2){
            a[x + 1][y] = 2;
            x++;
        }
        else if (ok == 1){
            a[x][y + 1] = 2;
            y++;
        }
    }

    for (int i = 1; i <= h; ++i){
        for (int j = 1; j <= w; ++j){
            if (b[i][j] == '#' && a[i][j] != 2) {cout << "Impossible"; return 0;}
        }
    }

    cout << "Possible";

    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,a[500][500],f[500],flag[500],ans;
bool fk[500],ff;
int read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	int kk=1,k=0;if (c=='-')kk=-1,c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}
signed main(){
	n=read();m=read();for (int i=1;i<=n;i++)for (int j=1;j<=m;j++)a[i][j]=read();
	for (int i=1;i<=n;i++)f[i]=1,flag[a[i][1]]++;ff=1;ans=1e9;
	while (ff){
		int k=0;for (int i=1;i<=m;i++)if (flag[i]>flag[k])k=i;
		ans=min(ans,flag[k]);fk[k]=1;
		for (int i=1;i<=n;i++){
			while (fk[a[i][f[i]]])flag[a[i][f[i]]]--,f[i]++,flag[a[i][f[i]]]++;
			ff&=f[i]<n+1;
		}
	}cout<<ans<<endl;
}


Measured memory_bytes: 1408
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 20){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

void solve(){
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N+1, INFL);
  rep(i, N) cin >> A[i];
  sort(A.begin(), A.end());
  ll sum = 0;
  rep(i, N-K){
    sum += A[i];
  }
  cout << sum << endl;
}

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


Measured memory_bytes: 1792
// Last Change: 08/26/2019 03:48:35.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll A, B;
  cin >> A >> B;

  if (A % 3 == 0 or B % 3 == 0 or (A + B) % 3 == 0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
}


Measured memory_bytes: 256
#ABC092-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
A=[0]+IL()+[0]
s=0
for i in range(n+1):
    s+=abs(A[i+1]-A[i])
for i in range(1,n+1):
    ans=s
    ans-=abs(A[i+1]-A[i])+abs(A[i]-A[i-1])
    ans+=abs(A[i+1]-A[i-1])
    print(ans)

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) 
#define repi(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v) rep(i,v.size()) {cin >> v[i];}
//最終奥義
//#define int long long
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }

signed main(void){
  int n,d;cin >> n >> d;
  
  cout << ceil(n / (float)(2*d + 1))  << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N = keyboard.nextInt();
		String S = keyboard.next();
		
		String[] ishi1 = S.split("");
		int count = 0;
		
		int[] Lkuro = new int[N];
		int[] Rshiro = new int[N];
		
		for (int i = 1; i < S.length(); i++) {
			if(ishi1[i-1].equals("#")) {
				Lkuro[i] = Lkuro[i-1] + 1;	
			}else {
				Lkuro[i] = Lkuro[i-1];
			}
		}
		
		for (int j = S.length() - 2; j >= 0; j--) {
			if(ishi1[j+1].equals(".")) {
				Rshiro[j] = Rshiro[j+1] + 1;	
			}else {
				Rshiro[j] = Rshiro[j+1];
			}
		}
		
		int kotae = 1000000;
		
		for(int k = 0; k < S.length(); k++) {
			kotae = Math.min(kotae, Lkuro[k]+ Rshiro[k]);
		}
		
		System.out.println(kotae);
		keyboard.close();
	}
}


Measured memory_bytes: 56844
#include <iostream>
#include <algorithm>
#include <iostream>

#include <vector>

#include <cassert>

#include <algorithm>

#include <functional>

#include <cmath>

#include <iomanip>

#include <limits>
#include <bits/stdc++.h>
#include<queue>
#include<type_traits>
#include<cstdint>
using namespace std;
int main() {
	long long n,m;
	cin >> n >> m;
	vector<pair<long long,long long>> vec(n);
	for(int i=0;i<n;i++){
	    long long x,y;
	    cin >> x >> y;
	    vec[i]=make_pair(x,y);
	}
	sort(vec.begin(),vec.end());
	int j=0;
	long long count=0;
	while(1){
	    if(vec[j].second <= m){
	        count += vec[j].first * vec[j].second;
	        m = m-vec[j].second;
	        j++;
	    }else{
	        count += vec[j].first*m;
	        break;
	    }
	}
	cout << count << endl;
}


Measured memory_bytes: 1792
macro_rules! read {
    () => {{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        input
    }};
}

fn read_to_vec<T: std::str::FromStr>() -> Vec<T> {
    read!().split_whitespace()
        .map(|e| e.parse::<T>().ok().unwrap())
        .collect()
}

fn main() {
    let mut input: Vec<i32> = read_to_vec();
    input.sort();
    println!("{}", input[0]+input[1]);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

char s[N],r[N];
int main(){
  int n;
  scanf("%d%s%s",&n,s,r);
  REP(i,n){
    int f=0;
    REPP(j,i,n){
      if(s[j]!=r[j-i]) f=1;
    }
    if(f==0){
      printf("%d\n",n+i); exit(0);
    }
  }
  printf("%d\n",2*n);
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<string.h>
#include<iostream>
#include<stdio.h>
using namespace std;

typedef long long ll;
ll n,k;
const ll N=1e5*2+10;
ll h[N];
ll ans=0;

int main(){
	cin>>n>>k;
	
	for(ll i=0; i<n; i++)
		cin>>h[i];
	
	sort(h,h+n);
	for(ll i=0; i<n-k; i++)
		ans+=h[i];
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
a=(1..5).map{gets.to_i}.sort{|s,t|s%10<=>t%10}
l=0
a.each_with_index{|e,i|
    if e%10 != 0
        l = i
        break
    end
}
for i in 0..4
    if a[i]%10 != 0 && i != l
        a[i] = (a[i]/10+1)*10
    end
end
p a.inject(:+)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define REP(i, n) for (ll i=0; i<(ll)n; ++i)
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  vll r(n);
  REP(i, n) cin >> r.at(i);
  ll minr=r.at(0), maxr=r.at(1) - r.at(0);
  rep(i, 1, n) {
    maxr = max(maxr, r.at(i) - minr);
    minr = min(minr, r.at(i));
  }
  cout << maxr << endl;
  return 0;
}



Measured memory_bytes: 4412
from collections import Counter

N = int(input())
a_list = list(map(int,input().split()))

a_dict = Counter(a_list)

new_a_dict = {}

for k,v in a_dict.items():
    for diff in [-1,0,1]:
        if k+diff in new_a_dict:
            new_a_dict[k+diff] += v
        else:
            new_a_dict[k+diff] = v

print(max(new_a_dict.values()))

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int k;
    cin>>k;
    int ans=-1;
    int res=0;
    for (int i=0;i<10000000;i++){
        res=(res*10+7)%k;
        if(res==0){
            ans=i+1;
            break;
        }
    }
    cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3612
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


n = int(input())
div = make_divisors(n)[1:]
s = set(make_divisors(n - 1))
for d in div:
    t = n
    while t % d == 0:
        t //= d
    if (t - 1) % d == 0:
        s.add(d)
print(len(s) - 1)


Measured memory_bytes: 39152
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

int N;
vector<int> e;  // e[i]: N! の約数iの個数

// m以上のeの要素数
int num(int m) {
  int count = 0;
  REP(i,0,N+1) if (e[i] >= m) ++count;
  return count;
}

int main()
{
  cin >> N;
  e.resize(N+1,0);

  REP(i,2,N+1) {
    int cur = i;
    REP(j,2,i+1) {
      while (cur % j == 0) {
        e[j]++;
        cur /= j;
      }
    }
  }

  int res = 0;
  res += num(74);               // 75
  res += num(24) * (num(2) - 1); // 25*3
  res += num(14) * (num(4) - 1); // 15*5
  res += num(4) * (num(4) - 1) * (num(2) - 2) / 2; // 5 * 5 * 3
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

#define NIL NULL

Node root;

void inorder(Node x){
  if(x==NIL) return;
  inorder(x->left);
  printf(" %d",x->key);
  inorder(x->right);
}

void preorder(Node x){
  if(x==NIL) return;
  printf(" %d",x->key);
  preorder(x->left);
  preorder(x->right);
}

Node treeMinimum(Node x){
  while(x->left!=NIL) x=x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL) x=x->right;
  return x;
}



Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u; 
  if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  if(x->right!=NIL) return treeMinimum(x->right);
  Node y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}
/*
void treeDelete(Node x){
Node y;
Node x;


}
*/

void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;

  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
 
  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL) root=z;
  else if(z->key < y->key) y->left=z;
  else y->right=z;
}

int main(){
  int n,i,x;
  char com[20];
  scanf("%d",&n); //n=命令の数//

  for(i=0;i<n;i++){
    scanf("%s",com);
    
    if(com[0]=='f'){
      scanf("%d",&x);
      Node t=treeSearch(root,x);
      if(t!=NIL) printf("yes\n");
      else printf("no\n");
    }else  if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }

    /* Cにて
       else if(com[0]=='d'){
       scanf("%d",&x);
       treeDelete(treeSearch(root,x));
       }*/
  }
  return 0;
}



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

#define ll long long


int main()
{

    char c1,c2;

    scanf("%c %c",&c1,&c2);

    int l1=c1;
    int l2=c2;


   if(l1>l2)
    for(int i=1;i<=(l1-48);i++){

     cout<<c2;
    }

  else{

  for(int i=1;i<=(l2-48);i++){

     cout<<c1;
    }

  }




    //cout<<l1-48<<" "<<l2-48<<" ";







    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	var ans = "Good"
	for i := 0; i < 3; i++ {
		if s[i] == s[i+1] {
			ans = "Bad"
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String work[] = new String[4];
        int table[][][] = new int[4][3][10];
 
        for(int a = 0; a < 4; a++){
            for(int b = 0; b < 3; b++){
                for(int c = 0; c < 10; c++)table[a][b][c] = 0;
            }
        }
 
        try {
            int N = Integer.parseInt(br.readLine());
 
            for(int loop = 0; loop < N; loop++){
                work = br.readLine().split("\\s+");
                table[Integer.parseInt(work[0])-1][Integer.parseInt(work[1])-1][Integer.parseInt(work[2])-1] += Integer.parseInt(work[3]);
            }
 
 
            print(table[0]);
            for(int i = 1; i <= 3; i++){
                System.out.printf("####################\n");
                print(table[i]);
            }
 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    private static void print(int house[][]){
 
        for(int row = 0; row < 3; row++){
            for(int col = 0; col < 10; col++){
                System.out.printf(" %d", house[row][col]);
            }
            System.out.printf("\n");
        }
    }
}


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

int main(void)
{
  int i=0,N;
  char s[4];
  char a[4] = "AC";
  char b[4] = "WA";
  char c[4] = "TLE";
  char d[4] = "RE";
  int c0=0,c1=0,c2=0,c3=0;
 scanf("%d",&N);
  while(i<N)
  {
scanf("%s",s);
 if(strcmp(a,s) == 0)
   c0= c0+1;
  else
   if(strcmp(b,s) == 0)
   c1= c1+1;
  else
    if(strcmp(c,s) == 0)
   c2= c2+1;
  else
   if(strcmp(d,s) == 0)
   c3=c3+1;
 
    i=i+1;
  }
 
 
  printf("AC x %d\n",c0);
  printf("WA x %d\n",c1);
  printf("TLE x %d\n",c2);
  printf("RE x %d\n",c3);
  
    return 0;
}


  
  

Measured memory_bytes: 1720
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include <numeric>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void printVector(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

char getLastWord(string s){
    return s[s.length() - 1];
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    int N;
    cin >> N;

    vector<string> W;
    FOR(i, 0, N){
        string s;
        cin >> s;
        W.push_back(s);
    }

    set<string> S;
    for(auto w : W){
        S.insert(w);
    }

    bool ret = true;
    if(W.size() != S.size()){
        ret = false;
    }
    else{
        char lastWord = getLastWord(W[0]);
        FOR(i, 1, N){
            if(W[i][0] != lastWord){
                ret = false;
            }
            lastWord = getLastWord(W[i]);
        }
    }

    if(ret){
        p("Yes");
    }else{
        p("No");
    }
    
    return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
	if (A+B < 2*C) {
		cout << X*A + Y*B << '\n';
	} else {
		int cnt = 2 * min(X, Y);
		cout << min(2 * max(X, Y) * C, cnt*C + A*(X-cnt/2) + B*(Y-cnt/2)) << '\n';
	}

	return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
x = list(map(int, input().split()))
ret = 10 ** 9
for i in range(N-K+1):
    init = abs(x[i])
    dist = abs(x[i]-x[i+K-1])
    l = init + dist
    init = abs(x[i+K-1])
    r = init + dist
    ret = min(ret, l, r)
print(ret)

Measured memory_bytes: 14384
#include<stdio.h>
#define N 100
#define W 0
#define G 1
#define B 2

void visit(int);
void dfs(void);

int n, m[N][N], color[N], d[N], f[N], t;

int main(){
  int u, v, k, i, j;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      m[i][j] = 0;
    }
  }
  for(i=0; i<n; i++){
    scanf("%d%d", &u, &k);
    u--;
    for(j=0; j<k; j++){
      scanf("%d", &v);
      v--;
      m[u][v] = 1;
    }
  }
  dfs();

  return 0;
}

void dfs(){
  int u;
  for(u=0; u<n; u++)color[u] = W;
  t = 0;
  for(u=0; u<n; u++){
    if(color[u] == W)visit(u);
  }
  for(u=0; u<n; u++){
    printf("%d %d %d\n", u+1, d[u], f[u]);
  }
}

void visit(int u){
  int v;
  color[u] = G;
  d[u] = ++t;
  for(v=0; v<n; v++){
    if(m[u][v] == 0)continue;
    if(color[v] == W){
      visit(v);
    }
  }
  color[u] = B;
  f[u] = ++t;
}



Measured memory_bytes: 2056
#include <iostream>
#include <string>

using namespace std;

class team_obj{
	public:
	int ansNum;
	int penalty;
	int wrongNum[10];
	int teamNum;
	int time;
};

void swap(int *a,int *b){
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main(){

	team_obj team[50];
	int ansLine[20];

	for(int i=0;i<50;i++){
		team[i].ansNum=0;
		team[i].penalty=0;
		for(int j=0;j<10;j++){
			team[i].wrongNum[j]=0;
		}
		team[i].teamNum=i;
	}

	int m,t,p,r;
	while(cin>>m>>t>>p>>r){
		if(m==0 && t==0 && p==0 && r==0)break;
			
		int tid,pid,tim;
		string str;
		for(int i=0;i<50;i++){
			team[i].ansNum=0;
			team[i].penalty=0;
			for(int j=0;j<10;j++){
				team[i].wrongNum[j]=0;
			}
			team[i].teamNum=i;
			team[i].time=0;
		}
		for(int i=0;i<20;i++)ansLine[i]=0;

		for(int i=0;i<r;i++){
			int jk;
			cin>>tim>>tid>>pid>>jk;
			tid--;
			pid--;

			if(team[tid].wrongNum[pid]==-1)continue;

			if(jk!=0){
				team[tid].wrongNum[pid]++;
			}
			else{
				team[tid].penalty+=team[tid].wrongNum[pid]*20;
				team[tid].wrongNum[pid]=-1;
				team[tid].ansNum++;
				team[tid].time+=tim;
			}
		}

		for(int i=0;i<t;i++){
			team[i].penalty+=team[i].time;
		}
/*
		for(int i=0;i<t;i++){
			cout<<"i="<<i<<endl;
			cout<<team[i].ansNum<<" "<<team[i].penalty<<endl;
		}
		*/
		//答え数のソートを行う。
		for(int i=0;i<t;i++){
			for(int j=t-1;j>i;j--){
				if(team[j].ansNum>=team[j-1].ansNum){
					int tmp = team[j].ansNum;
					team[j].ansNum = team[j-1].ansNum;
					team[j-1].ansNum =tmp;
					
					tmp = team[j].penalty;
					team[j].penalty = team[j-1].penalty;
					team[j-1].penalty = tmp;

					tmp = team[j].teamNum;
					team[j].teamNum = team[j-1].teamNum;
					team[j-1].teamNum = tmp;
				}
			}
		}
		//答え数の数を数える。
		for(int i=0;i<t;i++){
			ansLine[team[i].ansNum]++;
		}

		//次はペナルティにてソートを行う。
		//ペナルティにてソートを行う際、回答数が同じ場合のみ交換を行う。
		for(int i=0;i<t;i++){
			for(int j=t-1;j>i;j--){
				if(team[j].penalty<=team[j-1].penalty && team[j].ansNum == team[j-1].ansNum){
					int tmp = team[j].ansNum;
					team[j].ansNum = team[j-1].ansNum;
					team[j-1].ansNum =tmp;
					
					tmp = team[j].penalty;
					team[j].penalty = team[j-1].penalty;
					team[j-1].penalty = tmp;

					tmp = team[j].teamNum;
					team[j].teamNum = team[j-1].teamNum;
					team[j-1].teamNum = tmp;
				}
			}
		}
		//最後にチーム番号にてソートを行う。
		//回答数とペナルティ数が同じ場合のみソートを実行
		for(int i=0;i<t;i++){
			for(int j=t-1;j>i;j--){
				if(team[j].teamNum>=team[j-1].teamNum && team[j].ansNum == team[j-1].ansNum && team[j].penalty == team[j-1].penalty){
					int tmp = team[j].ansNum;
					team[j].ansNum = team[j-1].ansNum;
					team[j-1].ansNum =tmp;
					
					tmp = team[j].penalty;
					team[j].penalty = team[j-1].penalty;
					team[j-1].penalty = tmp;

					tmp = team[j].teamNum;
					team[j].teamNum = team[j-1].teamNum;
					team[j-1].teamNum = tmp;
				}
			}
		}

		//解答出力
		for(int i=0;i<t;i++){
			team[i].teamNum++;
			if(i!=t-1){
				cout<<team[i].teamNum;
				if(team[i].ansNum==team[i+1].ansNum && team[i].penalty == team[i+1].penalty){
					cout<<'=';
				}
				else{
					cout<<',';
				}
			}
			else{
				cout<<team[i].teamNum<<endl;
			}
		}
	}

	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
  int N;
  string c;
  cin >> N >> c;

  int l = 0;
  int r = N-1;
  int n = 0;
  while(l < r){
    while(1){
      if (l == N-1) break;
      else if (c[l] == 'R')++l;
      else break;
    }

    while(1){
      if (r == 0) break;
      else if (c[r] == 'W')--r;
      else break;
    }

    if (l >= r) break;

    char temp = c[l];
    c[l] = c[r];
    c[r] = temp;
    ++n;
  }

  cout << n << endl;
  return 0;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
int l,a,b,n;
string s;
int main()
{
    cin>>s;
    l=s.length();
    for(int i=0;i<l;i++)
    {
        if(s[i]=='S') a++;
        else
        {
            b++;
            if(a) a--,b--,n+=2;
        }
    }
    cout<<l-n;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
const long mod=1e9+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long fac[5<<17],inv[5<<17];
int N,M;
long comb(int a,int b){return fac[a]*inv[b]%mod*inv[a-b]%mod;}
main()
{
	cin>>N>>M;
	fac[0]=1;
	for(int i=1;i<=M;i++)fac[i]=fac[i-1]*i%mod;
	inv[M]=power(fac[M],mod-2);
	for(int i=M;i--;)inv[i]=inv[i+1]*(i+1)%mod;
	long ans=0;
	for(int i=0;i<=N;i++)
	{
		long now=comb(N,i)*comb(M-i,N-i)%mod*fac[N-i]%mod;
		if(i%2==0)ans+=now;
		else ans-=now;
	}
	ans=(ans%mod+mod)%mod;
	cout<<ans*fac[N]%mod*comb(M,N)%mod<<endl;
}


Measured memory_bytes: 11396
hash = {'I'=>1,'V'=>5,'X'=>10,'C'=>100,'D'=>500,'L'=>50,'M'=>1000}
while line = gets
  line.chomp!
  line = line.split("")
  ans =0
  i =0
  while i<line.size()-1
    a = hash[line[i]]
    b = hash[line[i+1]]
    if a<b
      ans += b-a
      i+=1
    else ans +=a
    end
    i+=1
  end
  if(i<line.size)
    ans+=hash[line[i]]
  end
  puts ans
end

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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

#define MOD (1000000007)

LL tbl[3000][3000];

int main()
{
	LL N, K;
	cin >> N >> K;

	REP(a, N + 1) {
		REP(b, a + 1) {
			if (a == 0 && b == 0) {
				tbl[a][b] = 1;
				continue;
			}
			LL v = 0;
			if (a - 1 >= 0 && b - 1 >= 0) {
				v += tbl[a - 1][b - 1];
				v %= MOD;
			}
			if (a - 1 >= 0) {
				v += tbl[a - 1][b];
				v %= MOD;
			}
			tbl[a][b] = v;
		}
	}

	REP(i, K) {
		LL div = i + 1;

		LL a = tbl[K - 1][div - 1];
		LL b = tbl[N - K + 1][div];
		LL c = (a * b) % MOD;

		cout << c << endl;
	}


	return 0;
}


Measured memory_bytes: 45696
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = ~~arg[0];
    const S = arg.slice(1, N + 1).map(n=>~~n);
    
    let now = 1;
    let cnt = 0;
    
    while(now !== 2) {
        now = S[now - 1];
        cnt++;
        
        if(cnt > N) {
            console.log(-1);
            return;
        }
    }
    
    console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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


using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main(){

	int n;
	cin >> n;

	ll ans = 0;
	int m = n;

	vector<int> v(100, 0);
	
	FOR(i, 1, n + 1) {
		int a = i % 10;
		if (a == 0)continue;
		int j = i;
		while (j >= 10) {
			j /= 10;
		}
		v[j * 10 + a]++;
	}


	FOR(i, 10, 100) {
		FOR(j, 10, 100) {
			if (i % 10 == j / 10 && i / 10 == j % 10)ans += v[i] * v[j];
		}
	}
	cout << ans << endl;


}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
    static int H[1500000],W[1500000];
    int N=0,M=0;
    while (cin >> N >> M && N!=0){
        int h[1500]={},w[1500]={};
        for (int i=1; i<=N; i++){
            cin >> h[i];
            h[i] += h[i-1];
        }
        for (int i=1; i<=M; i++){
            cin >> w[i];
            w[i] += w[i-1];
        }
        for (int i=0; i<1500000; i++){
            H[i]=0;
            W[i]=0;
        }
        for (int i=0; i<N; i++){
            for (int j=i+1; j<=N; j++){
                H[h[j]-h[i]]+=1;
            }
        }
        for (int i=0; i<M; i++){
            for (int j=i+1; j<=M; j++){
                W[w[j]-w[i]]+=1;
            }
        }
        int ans=0;
        for (int i=0; i<1500000; i++){
            ans+=H[i]*W[i];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 14704
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

int n, a, b;
int h[100005];

int f(LL m) {
	LL sum = 0;
	for (int i = 0; i < n; i++) {
		LL now = h[i] - b * m;
		if (now < 0) now = 0;
		sum += (now + a - 1) / a;
	}
	return (sum <= m);
}

int main()
{
	scanf("%d %d %d", &n, &a, &b);
	a -= b;
	for (int i = 0; i < n; i++) scanf("%d", &h[i]);
	int lo = 1, hi = 1000000000;
	while (lo < hi) {
		int mid = (lo + hi) / 2;
		if (f(mid)) hi = mid;
		else lo = mid + 1;
	}
	printf("%d\n", lo);

	return 0;
}


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

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())

#define REP(a, b) for (int a = 0; a < (b); a++)
#define FOR(a, b, c) for (int a = (b); a <= (c); a++)
#define REPD(a, b) for (int a = (b) - 1; a >= 0; a--)
#define FORD(a, b, c) for (int a = (b); a >= (c); a--)

#define MIN(a, b) (a) = min((a), (b))
#define MAX(a, b) (a) = max((a), (b))

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2> &p) {
  return is >> p.fi >> p.se;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n;
  cin >> k;
  vi a(n);
  REP(i, n) {
    cin >> a[i];
  }
  vi dp(n, 1e9 + 100);
  dp[0] = 0;
  REP(i, n) {
    FOR(j, 1, k) {
      if (i + j >= n) break;
      MIN(dp[i + j], dp[i] + abs(a[i] - a[i + j]));
    }
  }
  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int cnt=0;
  if(a%2==0&&a==b&&b==c){
    cout << -1 << endl;
  }
  else{
    while(a%2==0&&b%2==0&&c%2==0){
      cnt++;
      int s=a;
      int t=b;
      int u=c;
      a=t/2+u/2;
      b=u/2+s/2;       
      c=s/2+t/2;
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
int n;
cin>>n;
vector<int>a(n);
for(int i =0;i<n;i++)
{
    cin>>a[i];
}
sort(a.rbegin(),a.rend());
int sum1=0,sum2=0;
for(int i =0;i<n;i++)
{
    if(i%2==0) sum1+= a[i];
    else sum2+=a[i];
}
cout<<sum1-sum2;
return 0;
}


Measured memory_bytes: 764
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int A = int.Parse(s[0]);
        int B = int.Parse(s[1]);
        int C = int.Parse(s[2]);
        Console.WriteLine(A + B >= C ? "Yes" : "No");
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  if(n/10 == 9 || n%10 == 9)
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int prime[100001];
vector<int> like_2017;

bool is_prime[100001];

int main(){
  fill(is_prime, is_prime + 100001, true);
  is_prime[0] = is_prime[1] = false;
  is_prime[2] = true;
  for(int i = 2; i * 2 < 100001; i++) is_prime[2*i] = false;
  for(int i = 3; i < 100001; i+=2){
    if(is_prime[i] && is_prime[(i+1)/2]) like_2017.push_back(i);
    if(is_prime[i])
      for(int j = 2; i * j < 100001; j++) is_prime[i * j] = false;
  }
  int q;
  cin >> q;
  for(int i = 0; i < q; i++){
    int l, r;
    cin >> l >> r;
    cout << upper_bound(all(like_2017), r) - lower_bound(all(like_2017), l)<<endl;
  }
}

Measured memory_bytes: 768