akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair 
#define F first
#define S second
typedef long long ll;
#define REP(i,a,b) for(ll i=a; i<(ll)b; i++)
#define PER(i,a,b) for(ll i=b-1; i>=(ll)a; i--)
#define all(v) (v).begin(),(v).end()
#define fill(v,n) fill(v.begin(),v.end(),n)
#define deb(sum) cout << #sum <<"="<< sum <<"\n"
#define lpi(v,x) (lower_bound(all(v),x)-v.begin()) //lowermost possible index
#define upi(v,x) (upper_bound(all(v),x)-v.begin()) //uppermost possible index
#define bpc(n) __builtin_popcountll(n)
//#define PI 3.1415926535897932384626
#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL);
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<pair<int,int>> vii;
const ll INF = 9223372036854775807;
const ll mod = 1000000007;
const long double PI = acos(-1.0);
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    ll res = (a * b) / gcd(a, b);
    return res;
}
bool isprime(ll n){
    for(ll i=2; i*i<=n; i++){
        //i and itself are factors of prime
        if(n%i == 0)
            return false;
    }
    return true;
}
vector<ll> factors(ll n){
    vector<ll> v;
    for(ll i=1; i*i<=n; i++){
        if(n%i == 0){
            v.PB(i);
            if(i != n/i){
                v.PB(n/i);
            }
        }
    }
    return v;
}
ll power(ll a, ll b) // O(log(b))
{
    ll ans = 1;
    b = b % mod; //if b is larger than or equal to mod
    while (b > 0)
    {
        if (b & 1) //b is odd
        {
            ans = (ans * a) % mod;
        }
        //b is even
        b >>= 1;                       //b = b/2
        a = (a % mod * a % mod) % mod; //a =a^2
    }
    return ans;
}
void solve(){
    ll n,d;cin>>n>>d;
     ll x,y;
     ll cnt = 0;
    for(ll i=0; i<n; i++){
        cin>>x>>y;
        if(x*x+y*y<=d*d){
            cnt++;
        }
    }
    cout<<cnt;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    //cin.ignore();//ignores the buffer chars after cin like'\n'...,because getline will read this also
    //cin.ignore(numeric_limits<streamsize>::max(), '\n');//ignores buffer chars like '\n' until next line'\n;' comes or EOF occurs
    solve();
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 2e09

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(110000), dp(110000, INF);
    for (int i = 0; i < n; i++) cin >> h.at(i);
    dp.at(0) = 0;
    
    for (int i = 0; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp.at(i+j) = min(dp.at(i+j), dp.at(i)+abs(h.at(i)-h.at(i+j)));
        }
    }
    cout << dp.at(n-1) << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    string a;
    cin >> a;
    int n = a.size();
    long long odp = 0;
    int doc = 0;
    for (int i = 0; i < n; ++i)
    {
        if (a[i] == 'W')
        {
            odp += i - doc;
            ++doc;
        }
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 720
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

template <typename T>
void printArr(const T * arr, int s, int fn) {
    for (int i = s; i <= fn; ++ i) cout << arr[i] << " ";
    cout << '\n';
}

template <typename T>
long long minArr(const T * arr, int s, int fn) {
    ll res = 1e16 + 1;
    for (int i = s; i <= fn; ++ i) {
        res = min(res, arr[i]);
    }
    return res;
}

template <typename T>
void printVec(const T * arr) {
    for (int i = 0; i < sz(arr); ++ i) cout << arr[i] << " ";
    cout << '\n';
}

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

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

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 1e5 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int main () {
    to_pray();

    double a, b;
    cin >> a >> b;

    double c = a / b;
    cout << fixed << setprecision(8) << c;

    //eprintf("%.18lf seconds\n", (double)clock() / CLOCKS_PER_SEC);

    cout << '\n';
    
    return 0;
}

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

int main(void){
  long double a,b,h,m;cin>>a>>b>>h>>m;
  long double dig=PI/180*360*((h+m/60)/12-(m/60));
  printf("%20.20Lf\n",sqrtl(a*a+b*b-2*a*b*cosl(dig)));
  return 0;
}


Measured memory_bytes: 4164
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.FileReader;
import java.io.FileWriter;

import java.util.*;
import java.util.stream.LongStream;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    /* 標準入力数値配列用 long */
    static long[] inputLongArr() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        long[] longarray = new long[strarray.length];
        for (int i = 0; i < longarray.length; i++) {
            longarray[i] = Long.parseLong(strarray[i]);
        }
        return longarray;
    }

    // 標準入力数値リスト用 int
    static List<Integer> inputIntList() throws Exception {
        List<String> strList = Arrays.asList(br.readLine().trim().split(" "));
        List<Integer> intList = new ArrayList<Integer>();
        for (String elem : strList){
            intList.add(Integer.parseInt(elem));
        }
        return intList;
    }

    // 標準入力数値配列用 integer 降順ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    /*標準入力long*/
    static long inputLong() throws Exception {
        return Long.parseLong(br.readLine());
    }

    /*標準入力long*/
    static int inputInt() throws Exception {
        return Integer.parseInt(br.readLine());
    }



    public static void main(String[] args) throws Exception {
        // write your code here
        String s = br.readLine();
        int n = s.length()-1;
        char [] cl = s.toCharArray();
        long sum = 0;
        for(int i=0; i< (Math.pow(2,n)); i++){
            StringBuilder sb = new StringBuilder();
            for(int j=0; j<n; j++){
                sb.append(cl[j]);
                if ((1&i>>j) == 1) {
                    sb.append('+');
                }
            }
            sb.append(cl[n]);
            String tmp = sb.toString();
            int st =0;
            for(int k = 0; k<tmp.length(); k++){
                if(tmp.charAt(k) == '+'){
                    sum += Long.parseLong(tmp.substring(st,k));
                    st = k+1;
                }
            }
            sum += Long.parseLong(tmp.substring(st));
        }
        
        System.out.println(sum);


    }

}



Measured memory_bytes: 33216
def main():
    N, Q = map(int, input().split())

    values = [0] * N
    links = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        links[a - 1].append(b - 1)
        links[b - 1].append(a - 1)
    for _ in range(Q):
        p, x = map(int, input().split())
        values[p - 1] += x

    s = [(0, -1)]
    while s:
        i, p = s.pop()
        for j in links[i]:
            if j == p:
                continue
            values[j] += values[i]
            s.append((j, i))
    print(*values)

main()

Measured memory_bytes: 60392
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] suit={"S","H","C","D"};
        Set<String> list = new HashSet<String>();
        for (int i = 0; i < n; i++) {
            list.add(br.readLine());
        }
        for (int i=0;i<4;i++) {
            for(int j=1;j<=13;j++){
                if(!list.contains(suit[i]+" "+j)){
                    System.out.println(suit[i]+" "+j);
                }
            }
        }
    }
}

Measured memory_bytes: 24476
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<queue>
#include<bitset>

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

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;

int main() {
	int n, i, j, k, l, m;
	vi a, b, c;

	cin >> n;
	b.resize(n);
	rep(i, n) {
		cin >> b[i];
	}
	rep(i, n) {
		k = b.size();
		m = -1;
		rep(j, k) {
			if (j + 1 == b[j])m = j;
		}
		if (m == -1) {
			cout << -1;
			return 0;
		}
		a.push_back(b[m]);
		b.erase(b.begin() + m);
	}
	rep(i, n) {
		cout << a[n - i - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include<vector>

#define INF 2e9

using namespace std;

vector<int>B[100000];

int main()
{
	int n,m,a,b;
	int i,ans=0;
	cin >> n >> m;

	vector<int>H(n);
	for (i = 0; i < n; i++)
	{
		cin >> H[i];
	}
	for (i = 0; i < m; i++)
	{
		cin >> a >> b;
		a--; b--;
		B[a].push_back(b);
		B[b].push_back(a);
	}
	for (i = 0; i < n; i++)
	{
		for (int j : B[i])
		{
			if (H[i] <= H[j])
			{
				ans++;
				break;
			}
		}
	}
	cout << n-ans << endl;
	return 0;
}

Measured memory_bytes: 8804
#include <iostream>
#include <vector>
#include <cstdlib>
#ifndef LIB_REPEAT_HPP
#define LIB_REPEAT_HPP
#define repeat(i,n) for (int i = 0; i < (n); ++i)
#define repeat_from(i,m,n) for (int i = (m); i < (n); ++i)
#define repeat_one(i,n) for (int i = 1; i <= (n); ++i)
#define repeat_rev(i,n) for (int i = (n)-1; 0 <= i; --i)
#define foreach(it, cont) for (decltype(cont.begin()) it = cont.begin(); it != cont.end(); ++it)
#endif
using namespace std;
#define INF (1<<28)
int main() {
    ios_base::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    vector<bool> b(N); repeat (i,N) { int a; cin >> a; b[i] = not not a; }
    vector<int>  p(M); repeat (i,M) cin >> p[i];
    int result = INF;
    repeat (d,2) {
        vector<int> c, q;
        repeat (i,N) if (b[i]) c.push_back(i);
        {
            int i = 0;
            repeat (j,M) {
                repeat (k,p[j]) {
                    if ((j+d) % 2) q.push_back(i);
                    i ++;
                }
            }
        }
        if (c.size() == q.size()) {
            int acc = 0;
            repeat (i, (int)c.size()) {
                acc += labs(c[i] - q[i]);
            }
            result = min(result, acc);
        }
    }
    cout << result << endl;
    return 0;
}

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

using namespace std;

#define int long long

const int N = (int)3e5, MOD = (int)1e9 + 7, INF = (int)3e18;

int mn = INF;
map <int, int> mp;
vector <int> v;

void rec(int cur_num = 0) {
    if (cur_num > 3234566667) {
        return;
    }
    ++mp[cur_num];
    int ld = cur_num % 10;
    rec(cur_num * 10 + ld);
    if (ld + 1 <= 9) {
        rec(cur_num * 10 + ld + 1);
    } 
    if (ld - 1 >= 0) {
        rec(cur_num * 10 + ld - 1);
    }
}

main() {
    ios :: sync_with_stdio(0);
    cin.tie(0);
    int k;
    cin >> k; 
    for (int i = 1; i <= 9; ++i) {
        rec(i);
    }
    int i = 0;
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        ++i;
        if (i == k) {
            cout << it -> first;
            return 0;
        }
    }
    return 0;
}

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

int main(){
    int n, k, cnt=0;
    cin >> n >> k;
    rep(i,n){
        int h;
        cin >> h;
        if(h>=k) cnt++;
    }
    cout << cnt << endl;
}

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

int main(){
  int N,M;
  string str[257];
  cin>>N;
  string str2[257];
  int f,k=0;
  for(int i=0;i<N;i++){
    cin>>str[i];
  }
  cin>>M;
  for(int i=0;i<M;i++){
    cin>>str2[i];
  }

  for(int i=0;i<M;i++){
    f=0;
    for(int j=0;j<N;j++){
      if(str2[i]==str[j]){
	if(k==0){
	  f=1;
	  k=1;
	  cout<<"Opened by "<<str2[i]<<endl;
	  break;
	}else{
	  k=0;
	  cout<<"Closed by "<<str2[i]<<endl;
	  break;
	}
      }
      else{
	if(j==N-1 && f==0) cout<<"Unknown "<<str2[i]<<endl;
      }
    }
  }
  return 0;
}
	

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

int main() {
  int n;
  while (cin >> n, n) {
    auto c = vector<int>(n);
    for (int i = 0; i < n; ++i) {
      string w; cin >> w;
      c[i] = w.length();
    }
    auto solve = [&]() {
      for (int i = 0; i < n; ++i) {
        auto sum = vector<int>{5, 7, 5, 7, 7};
        int pos = 0;
        for (int j = i; j < n; ++j) {
          if (sum[pos] == 0) ++pos;
          if (pos == 5) return i + 1;
          if (sum[pos] > 0) sum[pos] -= c[j];
        }
        if (sum[pos] == 0 && pos + 1 == 5) return i + 1;
      }
      return 0;
    };
    cout << solve() << endl;
  }
  return 0;
}



Measured memory_bytes: 3204
y,x=[int(i) for i in input().split()]
s=[[int(0)for i in range(x+1)]for j in range(y+1)]
for i in range(y):
    k=input().split()
    for j in range(x):
        s[i][j]=int(k[j])
for i in range(y):
    for j in range(x):
        s[i][x]=s[i][x]+s[i][j]
        s[y][j]=s[y][j]+s[i][j]
for i in range(y):
    s[y][x]=s[y][x]+s[i][x]
for i in range(y+1):
    for j in range(x):
        print(s[i][j],"",end="")
    print(s[i][x])

Measured memory_bytes: 8844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define all(v) (v.begin(),v.end())
#define ll long long
const int N=1010;
const int inf=2e9;
const ll mod=323232323;
ll gcd(int a,int b){
	while(b){
		int r=a%b;
		a=b;
		b=r;
	}
	return a;
}
int main(){
    ios::sync_with_stdio(0);
    int n,m;
    string s,t;
    cin>>n>>m;
    cin>>s>>t;
    ll len=n/gcd(n,m)*m;
    ll a=len/n;
    ll b=len/m;
    int i=0,j=0;
    bool flag=1;
    while(i<n||j<m){
		if(i*a<b*j){
			++i;
		}
		else if(i*a>b*j){
			++j;
		}
		else{
			if(s[i]!=t[j]){
				flag=0;
				break;
			}
			else{
				++i;
				++j;
			}
		}
    }
    cout<<(flag?len:-1)<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n,m;cin>>n>>m;
  P((n-1)*(m-1));
  return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

ll dp[111111];

int main(){
	
	int n,k;cin >> n >> k;
	vector<ll> v(n);
	REP(i,n)cin >> v[i];
	
	REP(i,111111)dp[i] = LLINF;
	dp[0] = 0;
	REP(i,n){
		REP(j,k){
		if(i+j+1 < n)dp[i+j+1] = min(dp[i+j+1], dp[i] + abs(v[i] - v[i+j+1]));
		}
	}
	
	cout << dp[n-1] << endl;
	return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF=1e9+7;

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

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

int main(){
    int s,i=1,a[1000001];
    memset(a,0,sizeof a);
    cin>>s;
    a[s]=1;
    while(1){
        i++;
        if(s%2==1){
            s=3*s+1;
        }else{
            s/=2;
        }
        if(a[s]!=0){
            cout<<i<<endl;
            return 0;
        }
        a[s]=i;
    }
    return 0;
}

//a=97,z=122

Measured memory_bytes: 4096
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int A[100010];
int ans[100010];
int main()
{
	int N;
	cin >> N;
	ll sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum += A[i];
	}
	A[N] = 0;
	ll s = 0;
	for (int i = 1; i < N; i += 2) s += A[i];
	ans[0] = sum - s * 2;
	for (int i = 0; i < N; i++) {
		ans[i + 1] = 2 * A[i] - ans[i];
	}
	for (int i = 0; i < N; i++) {
		cout << ans[i] << " " << endl;
	}
	cout << endl;
}


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

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  cout << 'A' << s2[0] << 'C' << endl;
}


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

class Program
{
    public void Slove()
    {   
        var inputs = Console.ReadLine().Split();
        int a = int.Parse(inputs[0]);
        int b = int.Parse(inputs[1]);
        bool judge = (a + 1) / 2 >= b;
        Console.WriteLine(judge ? "YES" : "NO");
    }
    static void Main(string[] args)
    {
        var p = new Program();
        p.Slove();
    }
}


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

int main(){
    int N; cin >> N;
    map<int,int> mp;

    for(int i=0; i<N; i++){
        int a; cin >> a;
        mp[a]++;
    }

    int res = 0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++){
        res += (itr->second)-1;
    }

    int operation = (res+1)/2;
    cout << N-2*operation << endl;

}

Measured memory_bytes: 4992
"use strict";
function main(input) {
  let kari = input[0].trim().split(" ");
  let n = parseInt(kari[0]);
  let r = parseInt(kari[1]);

  n = n.toString(r);

  console.log(n.length);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

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

int main(){
    string s;
    cin >> s;
    int a=0,b=0;
    rep(i,s.size()){
        if(s[i]=='0')a++;
        else b++;
    }
    cout << 2*min(a,b) << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;
int main(){
	double x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	//cout << sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2))<<endl;
	printf("%.8f\n", sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2)));
}


Measured memory_bytes: 3196
#include<stdio.h>

int main(){
    int A,B;
    scanf("%d%d",&A,&B);
    if(((A+B)%3)==0){
        printf("Possible\n");
    }else if((A%3)==0){
        printf("Possible\n");
    }else if((B%3)==0){
        printf("Possible\n");
    }else{
        printf("Impossible\n");
    }
}

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

#define HEIGHT 1010

int main(void){
  while(true){
    int n, m, a;
    cin >> n >> m >> a;
    if(n == 0 && m == 0 && a == 0){ break; }

    int h, p, q;
    vector<vector<pair<int, int> > > amida(HEIGHT + 1);
    for(int i = 0; i < m; i++){
      cin >> h >> p >> q;
      amida[h].push_back(make_pair(p, q));
      amida[h].push_back(make_pair(q, p));
    }

    for(int i = HEIGHT; i >= 0; i--){
      for(size_t j = 0; j < amida[i].size(); j++){
        if(amida[i][j].first == a){
          a = amida[i][j].second;
          break;
        }
      }
    }
    
    cout << a << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3076
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class AC>void r(AC &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n,m;
int main(){
	r(n);r(m);
	printf("%d\n",(n-1)*(m-1));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#define ll unsigned long long
using namespace std;
/*
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t; cin >> t;
    while (t--) {
        ll n; cin >> n;
        vector<ll> a(n), b;// A_B(n), B_A(n);
        unordered_map<ll, ll> A, B;
        ll cost = 0, flag = 0;

        for (int i = 0; i < n; i++) {
            cin >> a[i];
            if (A.find(a[i]) == A.end()) {
                        A[a[i]] = 1;
            }
            else
                A[a[i]] += 1;
        }
        for (int i = 0; i < n; i++) {
            ll temp; cin >> temp;
            auto it = find(a.begin(), a.end(), temp);
            if (it != a.end()) {
                a.erase(remove(a.begin(), a.end(), temp), a.end());
            }
            else
                b.push_back(temp);
        }
//        auto AB = set_difference(a.begin(), a.end(), b.begin(), b.end(), A_B.begin());
//        auto BA = set_difference(b.begin(), b.end(), a.begin(), a.end(), B_A.begin());
//

        if (a.size() != b.size() || (a.size()%2 != 0 || b.size()%2 != 0)) {
            flag = 1;
        }
        ll i = 0;
        while(i<a.size()) {
            if ((count(a.begin(), a.end(), a[i]) >= 2)) {
                for (auto& ip : b) {
                    if (count(a.begin(), a.end(), ip) < count(b.begin(), b.end(), ip) && count(b.begin(), b.end(), ip) >= 2) {
                        swap(ip, a[i]);
                        cout << ip << " " << a[i] << "\n";
                        cost += min(ip, a[i]);
                        break;
                    }
                }
            }
            i++;
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        cout << "\nA\n";
        for (auto ip : a) {
            cout << ip << " ";
        }
        cout << "\nB\n";
        for (auto ip : b) {
            cout << ip << " ";
        }
        if ( ! (a==b) ) {
            flag = 1;
        }
        if(flag == 0) cout << cost << "\n";
        else cout << -1 << "\n";

 1
 4
 1 1 2 2
 3 3 4 4

    }


}
*/
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll l, r, d;
    cin >> l >> r >> d;
    ll i = l, ans = 0;
    while (i <= r) {
        if (i % d == 0) {
            ans++;
            i+=d;
        }
        else
            i++;
    }
    cout << ans;
}


Measured memory_bytes: 3200
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn divisors(n: u64) -> Vec<u64> {
    let mut divisors: Vec<u64> = Vec::new();
    for i in 1..n {
        if i * i > n {
            break;
        }
        if n % i == 0 {
            if i != 1 {
                divisors.push(i);
            }
            if i * i != n {
                divisors.push(n / i);
            }
        }
    }
    divisors
}

fn main() {
    let n: u64 = input();
    let mod1_vec = divisors(n - 1);
    let mod0_vec = divisors(n);
    // println!("{:?}", mod0_vec);
    // println!("{:?}", mod1_vec);
    let mut count = 0usize;
    for m0 in mod0_vec {
        let mut buf = n;
        while buf % m0 == 0 {
            buf /= m0;
        }
        if buf % m0 == 1 {
            count += 1;
        }
        // println!("{}, {}, {}", buf, m0, buf%m0);
    }
    println!("{}", mod1_vec.len() + count);
}


Measured memory_bytes: 4352
n = gets.to_i
vs = gets.split(' ').map(&:to_i)

vs.sort!

numerator = vs[0] + vs[1]
denominator = 2

vs[2..-1].each do |v|
  numerator += v * denominator
  denominator *= 2
  gcd = numerator.gcd(denominator)
  numerator /= gcd
  denominator /= gcd
end

puts numerator / denominator.to_f



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

using namespace std;
typedef long long LL;
int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
const int mod = 1e9 + 7;
const int N = 5001;
int read() {
	int s = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
	return s * f;
}
void put(int x) {
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

struct edge {int x, y, next;} e[2 * N]; int len, last[N];
int tot[N], f[N][N], g[N], tmp[N];

void ins(int x, int y) {
	e[++len].x = x, e[len].y = y;
	e[len].next = last[x], last[x] = len;
}

int add(int x, int y) {
	x += y;
	return x >= mod ? x - mod : x;
}

int dec(int x, int y) {
	x -= y;
	return x < 0 ? x + mod : x;
}

void dfs(int x, int fa) {
	tot[x] = 1, f[x][1] = 1;
	for(int k = last[x]; k; k = e[k].next) {
		int y = e[k].y;
		if(y != fa) {
			dfs(y, x);
			for(int i = 1; i <= tot[x] + tot[y]; i++) tmp[i] = 0;
			for(int i = 1; i <= tot[x]; i++) {
				for(int j = 1; j <= tot[y]; j++) {
					tmp[i + j] = add(tmp[i + j], (LL)f[x][i] * f[y][j] % mod);
					if(!(j & 1)) tmp[i] = dec(tmp[i], (LL)f[x][i] * f[y][j] % mod * g[j] % mod);
				}
			} tot[x] += tot[y];
			for(int i = 1; i <= tot[x]; i++) f[x][i] = tmp[i];
		}
	}
}

int main() {
	int n = read();
	for(int i = 1; i < n; i++) {
		int x = read(), y = read();
		ins(x, y), ins(y, x);
	} for(int i = 2; i <= n; i += 2) {
		g[i] = 1;
		for(int j = i - 1; j >= 1; j -= 2) g[i] = (LL)g[i] * j % mod;
	} dfs(1, 0);
	int ans = 0;
	for(int i = 2; i <= n; i += 2) ans = add(ans, (LL)f[1][i] * g[i] % mod);
	put(ans), puts("");
	return 0;
}


Measured memory_bytes: 97152
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define LD long double

LL MOD = 1000000007;

bool find(vector<int> p, int x){
        for(int i = 0; i < p.size(); ++i){
            if(p[i] == x){
                return false;
            }
        }

        return true;
}

int main(){
    int x,n;
    cin >> x >> n;
    vector<int> p(n);

    for(int i = 0; i < n; ++i) cin >> p[i];

    for(int i = 0; i < x + 1; ++i){
        int a = x + (-1) * i;
        int b = x + 1 * i;

        if(find(p,a)){
            cout << a << endl;
            return 0;
        }
        if(find(p,b)){
            cout << b << endl;
            return 0;
        }
    }

    return 0;
}

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

int main() 
{
	int n;
	string str;
	
	cin>>n;
	
	cin>>str;
	
	int b,r;
	
	b=r=0;
	
	for(int i=0;i<n;i++)
	{
		if(str[i]=='R') r++;
		else b++;
	}
	
	if(r>b)
	{
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
N,W,*L=map(int,open(0).read().split())
d={}
for v,w,m in zip(*[iter(L)]*3):
	d[(v,w)]=d.get((v,w),0)+m
dp=[0]*(W+1)
for (v,w),m in d.items():
	cw,cv=w,v
	b=m.bit_length()
	for i in range(b):
		if i==b-1:
			w=cw*(m-2**(b-1)+1)
			v=cv*(m-2**(b-1)+1)
		for j in range(W,w-1,-1):
			t=dp[j-w]+v
			if t>dp[j]:dp[j]=t
		w*=2
		v*=2
print(dp[W])


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }
    int mod=1000000007;
    long long sum=0;
    for(long long tmp=0,i=1;i<n;i++){
        tmp+=a.at(i-1);
        tmp%=mod;
        sum+=tmp*a.at(i);
        sum%=mod;
    }
    cout<<sum<<endl;
    return 0;
}

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

struct Edge{
    int from,to;
    int cost;
};
using Graph=vector<vector<Edge>>;

const int LOG=22;
void cmax(int &lhs,int rhs){
    lhs=max(lhs,rhs);
}
int main(){
    int V,E,K;
    cin>>V>>E>>K;
    Graph g(V);
    for(int i=0;i<E;i++){
        int x,y,c;
        cin>>x>>y>>c;
        g[x].push_back({x,y,c});
    }
    vector<vector<vector<int>>> w(LOG,vector<vector<int>>(V,vector<int>(V,-1e9)));
    for(int i=0;i<V;i++){
        w[0][i][i]=0;
        for(auto &e:g[i]){
            cmax(w[0][e.from][e.to],e.cost);
        }
    }
    for(int k=0;k+1<LOG;k++){
        for(int i=0;i<V;i++){
            for(int j=0;j<V;j++){
                for(int mid=0;mid<V;mid++){
                    cmax(w[k+1][i][j],w[k][i][mid]+w[k][mid][j]);
                }
            }
        }
    }

    int lb=0;
    int ub=1e6+2;
    while(ub-lb>1){
        int mid=(lb+ub)/2;
        vector<int> dp(V,0);
        int res=0;
        for(int i=LOG-1;i>=0;i--){
            cmax(res,*max_element(dp.begin(),dp.end()));
            if((mid>>i)&1){
                vector<int> next(V,-1e9);
                for(int j=0;j<V;j++){
                    for(int k=0;k<V;k++){
                        cmax(next[k],dp[j]+w[i][j][k]);
                    }
                }
                dp=next;
            }
        }
        cmax(res,*max_element(dp.begin(),dp.end()));
        if(res>=K){
            ub=mid;
        }
        else{
            lb=mid;
        }
    }
    if(ub>K){
        cout<<-1<<endl;
        return 0;
    }
    else{
        cout<<ub<<endl;
        if(ub<=100){
            vector<vector<int>> dp(ub+1,vector<int>(V,0));
            vector<vector<int>> prev(ub+1,vector<int>(V,-1e9));
            for(int i=0;i<ub;i++){
                for(int j=0;j<V;j++){
                    for(auto &e:g[j]){
                        if(dp[i+1][e.to]<dp[i][e.from]+e.cost){
                            dp[i+1][e.to]=dp[i][e.from]+e.cost;
                            prev[i+1][e.to]=e.from;
                        }
                    }
                }
            }
            int x=max_element(dp[ub].begin(),dp[ub].end())-dp[ub].begin();
            vector<int> res(ub+1);
            for(int i=0;i<ub;i++){
                res[i]=x;
                x=prev[ub-i][x];
            }
            res[ub]=x;
            reverse(res.begin(),res.end());
            for(int i=0;i<=ub;i++){
                cout<<res[i]<<(i+1==ub ? "\n" : " ");
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 5456
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long int ll;

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

int main() {
	ll T;
	cin >> T;
	vector<ll> A(T), B(T), C(T), D(T);
	for (int i = 0; i < T; ++i) cin >> A[i] >> B[i] >> C[i] >> D[i];

	for (int i = 0; i < T; ++i) {
		ll a = A[i], b = B[i], c = C[i], d = D[i];

		if (b > a) cout << "No" << endl;
		else if (b > d) cout << "No" << endl;
		else if (b <= c) cout << "Yes" << endl;
		else {
			ll g = gcd(b, d);
			if (c < b - g + (a % g)) cout << "No" << endl;
			else cout << "Yes" << endl;
		}

	}
}

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

int main() {
  int n;
  ll c;
  cin >> n >> c;
  vector<ll> x(n), v(n), clock_ans(n), inv_clock_ans(n);
  ll ans1 = 0, ans2 = 0;
  ll eat = 0;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
    eat += v[i];
    ans1 = max(ans1, eat - x[i]);

    clock_ans[i] = ans1;
  }

  eat = 0;
  for (int i = n - 1; i >= 0; i--) {
    eat += v[i];
    ans2 = max(ans2, eat - (c - x[i]));

    inv_clock_ans[i] = ans2;
  }


  ll ans = max(ans1, ans2);
//  cout << ans << endl;

  eat = 0;
  for (int i = 0; i < n; i++) {
    eat += v[i];
    ll inv = (i == n - 1) ? 0 : inv_clock_ans[i + 1];
//    cout << "i: " << inv << endl;
    ans = max(ans, eat - x[i] * 2 + inv);
  }

  eat = 0;
  for (int i = n - 1; i >= 0; i--) {
    eat += v[i];
    ll clo = (i == 0) ? 0 : clock_ans[i - 1];
//    cout << "c: " << clo << endl;
    ans = max(ans, eat - (c - x[i]) * 2 + clo);
  }

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

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

signed main(){
    int N, a[101];
    int ans = 0;
    cin >> N;
    REP(i, N) {
        cin >> a[i];
        if(i % 2 == 0 && a[i] % 2 == 1) ans++;
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <numeric>

using namespace std;

int main() {
  int n, m, cost;
  int p[1000];
  while (true) {
    cin >> n >> m;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i < n; ++i) {
      cin >> p[i];
    }
    sort(p, p + n);
    cost = accumulate(p, p + n, 0);
    for (int i = n - m; i >= 0; i -= m) {
      cost -= p[i];
    }
    cout << cost << endl;
  }
}

Measured memory_bytes: 1180
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var input_lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
 
let count5 = 0; 
  let count7 = 0; 
  let result = 'NO'
reader.on('line', (line) => {
  input_lines = line.split(" ")
  
  for(let i = 0; i < input_lines.length; i++) {
  
    if(input_lines[i] == 5) {
      count5++
    }
    if(input_lines[i] == 7) {
      count7++
    }

   }
  
  if(count7 == 1 && count5 == 2) {
    result = 'YES'
  }
  
});
 
 
/* ーーーー入力ーーーー
ここに書くコードを変える
 
 
　 ーーーー出力ーーーー */
reader.on('close', () => {
  console.log(result);
});

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

using namespace std;

int main(){
    long long int H,N,maxA=0,ans=1e9;
    cin >> H >> N;
    vector<long long int> A(N),B(N);
    for(int i=0;i<N;i++){
        cin >> A[i] >> B[i];
        maxA = max(A[i],maxA);
    }

    vector<long long int> dp(H+maxA,1e9);

    dp[0] = 0;

    for(int i=1;i<H+maxA;i++){
        for(int j=0;j<N;j++){
            if(0<=i-A[j]){
                dp[i] = min(B[j]+dp[i-A[j]],dp[i]);
            }
        }
    }

    for(int i=H;i<H+maxA;i++){
        ans = min(ans,dp[i]);
    }

    cout << ans << endl;
}

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

int main(){
    ll A, B, K;
    cin >> A >> B >> K;
    if (A >= K) {
        A -= K;
        cout << A << " " << B << endl;
    }else if (A+B >= K) {
        B -= (K-A);
        A = 0;
        cout << A << " " << B << endl;
    }else cout << "0 0" << endl;
    return 0;
}


Measured memory_bytes: 256
/*
      author  : nishi5451
      created : 14.08.2020 17:23:41
*/

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


int main(){
    int n;
    cin >> n;
    rep(i,n){
        char c;
        cin >> c;
        if(c=='Y'){
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
int main(void){
	int a;
	int n[10000],m[10000];
	int h,i,j,k;
	h=0;
	do{
		h++;
		scanf("%d %d",&n[h],&m[h]);
	}while(n[h]!=0&&m[h]!=0);
	i=1;
	while(i<h){
		for(j=1;j<=n[i];j++){
			for(k=1;k<=m[i];k++){
				if(a==1){
					if(k%2!=0)printf("#");
					else printf(".");
				}
				else if(a==2){
					if(k%2==0)printf("#");
					else printf(".");
				}
			}
			printf("\n");
			a=(a==1)?2:1;
		}
		i++;
		printf("\n");
		a=1;
	}
	return 0;
}



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

using namespace std;

const int INF = 1e9 + 5;
const int N = 2e5 + 5;
const int MOD = 998244353;
const double EPS = 1e-9;

const double PI = acos(-1);



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int s, w;
    cin >> s >> w;
    if (w >= s)
        cout << "unsafe";
    else
        cout << "safe";
}

Measured memory_bytes: 3652
A, B = map(int,input().split())

S = [["."]*100 for i in range(100)]

for i in range(50,100):
    for j in range(0,100):
        S[i][j] = "#"

for i in range(B-1):
    S[2*(i//50)][(i%50)*2+(i//50)%2] = "#"
for i in range(A-1):
    S[2*(i//50)+51][(i%50)*2+(i//50)%2] = "."

print(100,100)
for i in range(100):
    print("".join(S[i]))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
   
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
   
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif
   
int main(){
  fastIO();
  int n;
  ll ans=0;
  cin>>n;
  vector<int>a(n);
  vector<int>seq;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int p1=0,p2=n-1;
  while(1){
    seq.push_back(a[p1]);
    seq.push_back(a[p2]);
    p1++,p2--;
    if(p1==p2)seq.push_back(a[p1]);
    if(p1>=p2)break;
  }
  for(int i=2;i<n;i+=2){
    ans+=seq[i-2]; 
  }
  for(int i=1;i<n;i+=2){
    if(i==n-1){
      ans+=seq[i-1];
    }else{
      ans+=min(seq[i-1],seq[i+1]);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4988
n = int(input())
person = [[0 for _ in range(10)] for _ in range(12)]

for _ in range(n):
  b, f, r, v = [int(m) for m in input().split()]
  person[3*(b-1)+f-1][r-1] += v

for index, p in enumerate(person):
  print(" "+" ".join([str(m) for m in p]))
  if (index+1)%3 == 0 and index < len(person)-1:
    print("####################")

Measured memory_bytes: 7640
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int dp[35][500005];

vector<int> z_function (string s) {
	int n = (int) s.length();
	vector<int> z (n);
	for (int i=1, l=0, r=0; i<n; ++i) {
		if (i <= r)
			z[i] = min (r-i+1, z[i-l]);
		while (i+z[i] < n && s[z[i]] == s[i+z[i]])
			++z[i];
		if (i+z[i]-1 > r)
			l = i,  r = i+z[i]-1;
	}
	return z;
}


bool get(int mid,int i)
{
	int ptr=i;
	ren(i,30,0)
	{
		if((1<<i)<=mid)
		{
			ptr=dp[i][ptr];
			mid-=(1<<i);
			if(ptr==-1)
			{
				return false;
			}
		}
	}
	return true;
}

int main()
{ios_base::sync_with_stdio(false);
string s,t;
cin>>s>>t;
int n=s.length(),m=t.length();
string tmp=s+s+s;
while(1)
{
	if(tmp.length()>=2*m)break;
	tmp+=s;
}

vii z = z_function(t+"#"+tmp);

rep(i,0,34)rep(j,0,500004)dp[i][j]=-1;

rep(i,0,n-1)
{
	if(z[i+m+1]==m)dp[0][i]=(i+m)%n;
	//o2(i,dp[0][i]);on;
}

rep(j,1,34)
{
	rep(i,0,n-1)
	{
		int x=dp[j-1][i];
		if(x==-1)dp[j][i]=-1;
		else dp[j][i]=dp[j-1][dp[j-1][i]];
	}
}



int lo=0,hi=1e9,mid,ans=0;

while(lo<=hi)
{
	mid=(lo+hi)/2;
	int foo=0;
	rep(i,0,n-1)
	{
		if(get(mid,i))
		{
			foo=1;
			break;
		}
	}
	if(foo)
	{
		lo=mid+1;ans=mid;
	}
	
	else
	{
		hi=mid-1;
	}
}

if(ans==1e9)ol("-1");
else ol(ans);

return 0;
}



Measured memory_bytes: 79352
N=int(input())
K=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(K[N-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include<iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
   	ll a,b,c;
   	cin >> a >> b >> c;
   	if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&b!=a)) cout << "Yes";
   	else cout << "No";
   	cout << "\n";
    return 0;
}



Measured memory_bytes: 764
#include<stdio.h>
#include<stdlib.h>
long long fun(long long ,long long );
long long fun(long long x,long long y)
{
    long long ans=0;
    long long tmp=y/x;
    while(tmp>=1)
    {
        ans++;
        tmp=tmp/2;
    }
    return ans;
}
int main()
{
    long long x,y;
    scanf("%lld%lld",&x,&y);
    printf("%lld\n",fun(x,y));
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, k;
map<int, int> mp;

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

  cin >> n >> k;
  REP(i, n) {
    int a;
    cin >> a;
    mp[a]++;
  }

  vector<int> g;
  for(auto const& u: mp) {
    g.push_back(u.second);
  }

  sort(g.begin(), g.end());

  int sum = mp.size();
  int ans = 0;

  REP(i, g.size()) {
    if(sum <= k) break;
    sum--;
    ans += g[i];
  }

  cout << ans << endl;
}


Measured memory_bytes: 10744
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

ll a[30];

int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);

	      	  string s;
	      	  cin >> s;

	      	  int n=s.size();
	      	  for(i=0;i<n;i++) a[s[i]-'a']++;

	      	  ll ans=1+(ll)n*((ll)n-1)/2;
	      	  for(i=0;i<26;i++){
	      		  if(a[i]>=2LL) ans-=a[i]*(a[i]-1)/2;
	      	  }

	      	  cout << ans << endl;

	          return 0;
}


Measured memory_bytes: 720